Solved

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

Posted on 2000-03-13
15
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

617 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