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

Re: [MacPerl] Sorting Arrays



I apologize for mistiming the code in my e-mail.  I guess I did need
more sleep : )  

However, the POD was indeed wrong.  It says to sort the values using the
word "keys".  I didn't think of using the word values, so I appreciate
the help.  However, as it turns out I can't use the elements if they are
in an array, so I was wondering if it was possible to sort the values of
the array while still keeping them in an array.

Jon and Joetta wrote:
> 
> 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
> 
> ===== Want to unsubscribe from this list?
> ===== Send mail with body "unsubscribe" to macperl-request@macperl.org

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