Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

perl CGI - How can I use an array in popup_menu?

Posted on 2007-03-22
5
Medium Priority
?
716 Views
Last Modified: 2010-05-18
In the following code I want to use an array to place the values instead of hard coding them in. Is this possible and what is the syntax?

start_form,
"What's your favorite color? ",
popup_menu(-name=>'color',
      -values=>['red','green','blue','chartreuse']),
end_form;

Thanks,
Frank
0
Comment
Question by:ibanja
[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
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 18777112
my @array = ('red','green','blue','chartreuse);
# just pass a reference to your array
popup_menu(-name=>'color',
      -values=> \@array
end_form;
0
 
LVL 84

Accepted Solution

by:
ozo earned 1000 total points
ID: 18777847
my $arrayref=['red','green','blue','chartreuse'];
print start_form,
"What's your favorite color? ",
popup_menu(-name=>'color',
      -values=>$arrayref),
end_form;
0
 

Author Comment

by:ibanja
ID: 18779309
teraplane,

Being new to perl I may be missing something obvious but I couldn't get the solution to work so I went with ozo's.  Thanks for the input though.
0
 
LVL 84

Expert Comment

by:ozo
ID: 18781961
my @array = ('red','green','blue','chartreuse);
# just pass a reference to your array
print popup_menu(-name=>'color',
      -values=> \@array),
end_form;
#or create a new reference containing your array
print popup_menu(-name=>'color',
      -values=> [@array]),
end_form;
0
 

Author Comment

by:ibanja
ID: 18782330
Thanks ozo,

I have also discovered a missing single quote after chartreuse.

my @array = ('red','green','blue','chartreuse');

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

610 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