in reply to Re: sort hash by value
in thread sort hash by value
The Perlmonks collective seems to be having a few problems today. Left off the closing paren:
Or, alternatively, there's an extra one before "keys". ( keys %hash doesn't need parens for sort -- the parens are only needed for foreach.)foreach (sort { $hash{$a} <=> $hash{$b} || $a cmp +$b } (keys %hash) )
And I avoid the use of || in these cases, because of precedence worries. Use or, and parens if needed, and eliminate one more worry.
Update: Changed value comparison to numeric, per greywolf.
-QM
--
Quantum Mechanics: The dreams stuff is made of
In Section
Seekers of Perl Wisdom