[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Sorting Arrays



You are sorting the keys rather than the values... try something like

@test = sort { $a cmp $b } values %test;


>I know I have done this routine before but it has been awhile.  I am
>trying to sort the values of an array.  I went to run a test script (see
>below) using the perlfunc.pod as guidance.  However, the sort doesn't
>sort the values but the keys.  Am I missing something here.....
>
>
>$test{'1'} = "z";
>$test{'2'} = "a";
>$test{'3'} = "q";
>
>@test = sort { $age{$a} <=> $age{$a} } keys %test;
>
>foreach $element(@test)
> {
>    print "$element\n";
> }
>
>The output is:
>
>1
>2
>3


--
Matthew Zandstra
0171 249 4468  http://www.corrosive.co.uk/


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org