- or download this
use Tie::Hash::Sorted;
my %ages = ( 'John' => 33,
'Jacob' => 29,
...
'Heimer' => 48,
'Smitz' => 12,
);
- or download this
my $sort_by_numeric_value = sub {
my $hash = shift;
sort {$hash->{$b} <=> $hash->{$a}} keys %$hash ;
};
- or download this
tie my %sorted_ages, 'Tie::Hash::Sorted',
'Hash' => \ %ages,
'Sort_Routine' => $sort_by_numeric_value;
- or download this
for my $name ( keys %sorted_ages ) {
print "$name is $sorted_ages{$name} years old.\n";
}