Link to home
Start Free TrialLog in
Avatar of ibanja
ibanja

asked on

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
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

my @array = ('red','green','blue','chartreuse);
# just pass a reference to your array
popup_menu(-name=>'color',
      -values=> \@array
end_form;
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ibanja
ibanja

ASKER

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.
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;
Avatar of ibanja

ASKER

Thanks ozo,

I have also discovered a missing single quote after chartreuse.

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