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


in reply to Twice the pleasure of sorting a hash

Use following code for sorting

sort {$tmp = $saved_key{$b} <=> $saved_key{$a}; $tmp = $a cmp $b if ($tmp == 0); $tmp} keys %saved_key

Temporary variable is not needed of course