• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 774
  • Last Modified:

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

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
ibanja
Asked:
ibanja
  • 2
  • 2
1 Solution
 
Kim RyanIT ConsultantCommented:
my @array = ('red','green','blue','chartreuse);
# just pass a reference to your array
popup_menu(-name=>'color',
      -values=> \@array
end_form;
0
 
ozoCommented:
my $arrayref=['red','green','blue','chartreuse'];
print start_form,
"What's your favorite color? ",
popup_menu(-name=>'color',
      -values=>$arrayref),
end_form;
0
 
ibanjaAuthor Commented:
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
 
ozoCommented:
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
 
ibanjaAuthor Commented:
Thanks ozo,

I have also discovered a missing single quote after chartreuse.

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now