in reply to sorting a hash

Hi, Try this,

use strict; use warnings; my %hash = ( 5.764 => 'a', 3.24 => 'b', 4.6 => 'c'); print "$_\t$hash{$_}\n" for reverse sort keys %hash; __END__ 5.764 a 4.6 c 3.24 b

You should view How (Not) To Ask A Question.

Regards,
Velusamy R.


eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
Re^2: sorting a hash
by fishbot_v2 (Chaplain) on Feb 28, 2006 at 13:00 UTC

    The OP doesn't state this clearly, but I assume that he means numerically sorted, rather than lexically.

    print "$_\t$hash{$_}\n" for reverse sort { $a <=> $b } keys %hash; # or simply print "$_\t$hash{$_}\n" for sort { $b <=> $a } keys %hash;