Solved

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

Posted on 2000-03-13
15
225 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
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…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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