Sort Hash by Keys in Reverse Order : sort « Hash « Perl






Sort Hash by Keys in Reverse Order

    

%salary = ("P"  => 10,
           "S"  => 12,
           "C"  => 5,
           "S"  => 6,
           "L"  => 11,
           "D"  => 8,
);
foreach $key (reverse sort(keys %salary)) {
   printf "\t% -20s%5d\n", $key, $salary{$key};
}

   
    
    
    
  








Related examples in the same category

1.Hash Value Sorting
2.Numerically Sort a Hash by Values in Ascending Order
3.Numerically Sort a Hash by Values in Descending Order
4.Sort Hash by Keys Numerically
5.Sort keys in a hash
6.Sort values in a hash
7.Sorting a Hash
8.Ordered hash
9.Using customized function to sort keys in a hash