in reply to Sorting an array II

What you are looking for (if I understand you right) is the keys of %array sorted by their values.

Try this (see the -values line):

popup_menu(-name=>"array", -values=>[sort {$array{$a} <=> $array{$b}} keys %array], -labels=>\%array, -default=>$array1, -class=>"formfield")

BTW, why did you name a hash "%array" ;-)?

Update: Here's a quick test:

use CGI qw/:standard/; my %array = (a => 2, b=>1, c=>3); print popup_menu(-name=>'test', -values=>[sort {$array{$a} <=> $array{$b}} keys %array], -labels=>\%array) __END__ <select name="test"> <option value="b">1</option> <option value="a">2</option> <option value="c">3</option> </select>

Replies are listed 'Best First'.
Re: Re: Sorting an array II
by powerhouse (Friar) on Mar 03, 2003 at 19:07 UTC
    >BTW, why did you name a hash "%array"?

    Actually I did not, I just put that in the code I put on here, as it was shorter ;o)

    Here is what the real name is: max_go_array ( This site is pretty big, with tons of variables, I put the word array at the end so I know what it is, and where to look for it :o) )

    Thank you, this is what worked:
    {$max_go_array{$a} <=> $max_go_array{$b}}

    Putting that in the popup_menu worked. Thank you, VERY much!!


    thx,
    Richard