Solved

Pass an array to the CGI.pl Popup menu creation procedure

Posted on 2000-03-13
15
219 Views
Last Modified: 2008-03-03
I have an associative array that looks like this:
%label = ("Value 01", "label 01", "Value 02","label 02", "Value 03", "Label 03");

I want to pass it to the following function from the CGI.pl module:

# ====== create the actual popup form
print popup_menu (      -name => "$name",
                  -values =>[@values],
                  -labels => {%label},
                  -default => "$default"
                  );

# = end of ===== create the actual popup form

It doesn't work.

Can anyone help?

0
Comment
Question by:sstouk
  • 7
  • 2
  • 2
  • +3
15 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2614133
you have to change

-labels => {%label},

to

-labels => {\%label},
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2614173
Taken form the CGI.pm documentation, try
passing a pointer to the hash address. Also no need for {} to create an annonymous array.
 
-labels=> \%label,
0
 
LVL 6

Author Comment

by:sstouk
ID: 2614189
It displays Values instead of Labels.
0
 
LVL 6

Author Comment

by:sstouk
ID: 2614194
Maneshr's suggestion displays Values instead of labels and teraplane's suggestion displays only first Label correctly and the rest are Values instead of labels in the actual form.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2614259
Perhaps you could try constructing your hash as:
%label =
(
  "Value 01" => "label 01",
  "Value 02" => "label 02",
  "Value 03" => "Label 03"
);
0
 
LVL 6

Author Comment

by:sstouk
ID: 2614291
OK.
Just tested it,
still displays values.
Looks like the way of constructing doesn't have any relevance.
.....
The only way I can make it work if I make something like below inside the constructing procedure, but it limits me and makes the code clumzy...

Anyone got a better Idea than this?

-labels =>
{"$values[0]" => "$labels[0]",
  "$values[1]" => "$labels[1]",
  "$values[2]" => "$labels[2]",
  "$values[3]" => "$labels[3]",
  "$values[4]" => "$labels[4]",
},
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2614365
@associations{@values} = @labels;
......
-labels=> \%associations,



0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:PC_User321
ID: 2614391
If you want the quotes, try
@associations{qw(@values)} = qw(@labels);


0
 
LVL 6

Author Comment

by:sstouk
ID: 2614409
I tried the following:


@valuetemp = ("1","2","3");

@labeltemp = ("Label 01","Label 02","Label 03");

@assosiation{@valuetemp} = @labeltemp;

print popup_menu (      
-name => "$name",
-values =>[@valuetemp],
-labels => \%association,
-default => "$default"
                  );

This still never prints the Labels.

I tried to use @assosiation{@labeltemp} = @valuetemp;

I tried -labels => {\%association},
I tried -labels => %association,

Never ever it prints Labels instead of Values in my case.

If You have such a script that is working, show it please.




0
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 2614424
print popup_menu (
 -name => $name,
 -values =>[keys %label],
 -labels => \%label,
 -default => $default,
);
0
 
LVL 84

Expert Comment

by:ozo
ID: 2614439
Name "main::association" used only once: possible typo at - line 11 (#1)
Name "main::assosiation" used only once: possible typo at - line 6 (#1)
0
 
LVL 6

Author Comment

by:sstouk
ID: 2614450
I tried the following:


@valuetemp = ("1","2","3");

@labeltemp = ("Label 01","Label 02","Label 03");

@assosiation{@valuetemp} = @labeltemp;

print popup_menu (      
-name => "$name",
-values =>[@valuetemp],
-labels => \%association,
-default => "$default"
                  );

This still never prints the Labels.

I tried to use @assosiation{@labeltemp} = @valuetemp;

I tried -labels => {\%association},
I tried -labels => %association,

Never ever it prints Labels instead of Values in my case.

If You have such a script that is working, show it please.




0
 
LVL 6

Author Comment

by:sstouk
ID: 2614453
I apologise for mistakenly pressing "refresh" on the Explorer where the above comment was submitted. So it is submitted twice now. Please ignore it.

I am testing the ozo's suggestion now.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 2614457
Is this what you're looking for?

%label = ("Value 01", "label 01", "Value 02","label 02", "Value 03", "Label 03");

print popup_menu ( -name => "$name",
-values =>[ sort keys(%label) ],
-labels => \%label,
-default => "$default"
);
0
 
LVL 6

Author Comment

by:sstouk
ID: 2614515
Thank you very much.

Your example worked well.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now