in reply to CGI's "popup_menu" Using Hash Reference
As it stands now, you're passing into -values a structure like this:
when what you need to do is pass a structure like this as the -values parameter: [ '1', '2' ], and this as the -labels parameter:[ { '1' => { 'Author' => 'Mike', 'idAuthor' => '1' }, '2' => { 'Author' => 'Cecil', 'idAuthor' => '2' } } ]
So the question is, how do you go from one to the other? As with many structure reformulations, the answer is with a clever use of map:{ '1' => 'Mike', '2' => 'Cecil' }
If you don't like the order authors are shown in once you have ten or more, change the sort call above so that it sorts numerically.my $values_list = [ sort(keys(%$hash_ref)) ]; my $labels_href = { map {$_->{idAuthor} => $_->{Author}} values(%$hash_ref) }; print $cgi->popup_menu(-name=>'menu_name', -values=>$values_list, -labels=>$labels_href);
@/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
|
|---|