"Ok, I know you can't actually sort a hash.."
Of course you can sort a hash. You can sort a hash anyway you like. What you cannot rely on however, is the unsorted ordering in a hash.
Anyway, back to your problem at hand - all you really need to get your desired output is:
for my $person (sort {$age{$b}<=>$age{$a}} keys %age) { print "$person is $age{$person}\n"; }
There is really no need for the intermediate array, that is just un-necessarily complicating things.
Cheers,
Darren :)
In reply to Re: Sorting a hash by values...
by McDarren
in thread Sorting a hash by values...
by chinamox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |