danj35 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I need to sort my list of hash values alphabetically. I know how to sort the keys already, but swapping my keys for values won't work here as some of the values are the same. My Hash list looks like this:
my %hash = { 5328 => High 26191 => Very High 57491 => Low 4915 => High 1499 => Very High 999 => Low 4323 => Average 4314 => High
The code I have to sort the list by keys looks like this:
foreach my $key ( sort keys %hash ) { print "key: " . $key . " value: " . $hash{$key} . "\n"; }
Scowered through some of the 'howto's' for this, but none seem to have any info on sorting when some values might be the same. A simple link would be great.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort Hash Values Alphabetically
by kennethk (Abbot) on May 25, 2010 at 14:19 UTC | |
by danj35 (Sexton) on May 25, 2010 at 14:27 UTC | |
|
Re: Sort Hash Values Alphabetically
by ack (Deacon) on May 25, 2010 at 16:27 UTC |