Help for this page

Select Code to Download


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