vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:
Is this is the correct and best way to sort an hash by values so I can get the keys according to that ? do you know any other way to do this task. efficient way always welcome
my %hash = (value1 => 345, value2 => 132, value3 => 1, value4 => 12, v +alue5=>978); my (@keys,$key); @keys = sort { $hash{$a} <=> $hash{$b} } keys %hash; foreach $key (@keys) { print "$key: $hash{$key}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash sort by the values and get the keys
by ELISHEVA (Prior) on May 05, 2009 at 06:12 UTC | |
by GrandFather (Saint) on May 05, 2009 at 22:04 UTC | |
|
Re: hash sort by the values and get the keys
by leslie (Pilgrim) on May 05, 2009 at 05:07 UTC | |
|
Re: hash sort by the values and get the keys
by Bloodnok (Vicar) on May 05, 2009 at 09:32 UTC |