Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2000-03-13
15
Medium Priority
?
252 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 85

Accepted Solution

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

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
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…
Six Sigma Control Plans

927 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