Solved

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

Posted on 2007-03-22
5
712 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 250 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

Industry Leaders: 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!

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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

696 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