http://www.perlmonks.org?node_id=537852


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:
foreach (sort { $hash{$a} <=> $hash{$b} || $a cmp +$b } (keys %hash) )
Or, alternatively, there's an extra one before "keys". ( keys %hash doesn't need parens for sort -- the parens are only needed for foreach.)

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