print "$_ => $hash{$_}\n" for sort {$hash{$b} <=> $hash{$a} || $a cmp
+$b} keys %hash;
Sort in reverse numerical order, and in cases of collisions, in ASCIIbetical order for names. If you wish to be nice and use proper Unicode collation for peoples' names, use Unicode::Collate for the part of the sort routine that comes after the || operator.
use strict;
use warnings;
use Unicode::Collate;
use utf8;
binmode STDOUT, ':encoding(UTF-8)';
my $collator = Unicode::Collate->new();
my %hash = (
'James' => 43,
'John' => 2,
'Jeffrey' => 18,
'Jamie' => 19,
'Joseph' => 43,
'Ĵan' => 43, # Was latin capital letter j with circumflex be
+fore PerlMonks got a hold of it
'Janice' => 12,
'Jasmin' => 7,
'Justin' => 31,
'José' => 43,
'Jordan' => 43,
);
print "$_ => $hash{$_}\n"
for sort {$hash{$b} <=> $hash{$a} || $collator->cmp($a,$b)} keys %
+hash;
(Sorry about PerlMonks breaking latin capital letter j with circumflex)