Tony1 has asked for the wisdom of the Perl Monks concerning the following question:
thanks in advanceuse Tie::Hash::Sorted; my %ages = ( 'John' => 33, 'Jacob' => 29, 'Jingle' => 15, 'Heimer' => 48, 'Smitz' => 12, ); my $sort_by_numeric_value = sub { my $hash = shift; [ sort {$hash->{$b} <=> $hash->{$a}} keys %$hash ]; }; tie my %sorted_ages, 'Tie::Hash::Sorted', 'Hash' => \ %ages, 'Sort_Routine' => $sort_by_numeric_value; for my $name ( keys %sorted_ages ) { print "$name is $sorted_ages{$name} years old.\n"; }
May 19, 2008 at 23:08 UTC, Janitored by McDarren. Added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: meaning for the hash code
by Lu. (Hermit) on May 13, 2008 at 07:58 UTC | |
|
Re: meaning for the hash code
by sandboxed (Sexton) on May 13, 2008 at 08:09 UTC | |
| |
|
Re: meaning for the hash code
by alexm (Chaplain) on May 13, 2008 at 13:00 UTC | |
by Tony1 (Novice) on May 14, 2008 at 06:23 UTC |