Solved

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

Posted on 2000-03-13
15
226 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
collecting information 2 179
Using Perl to parse rows 7 97
PHP pack() : What exactly is meant by signed char and unsigned char? 7 118
quoting a comma separated list 20 86
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

791 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