Solved

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

Posted on 2007-03-22
5
699 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
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks ozo,

I have also discovered a missing single quote after chartreuse.

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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now