Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Removing file extension within a file. 4 98
crawling gofundme 4 132
Perl Script - Remove column of data based on column value 2 53
Perl script to process a .csv file 18 44
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 …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

791 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