It's easy to sort a hash by it's key, but to sort by it's value, the subroutines below are a life safer! From: http://www.devdaily.com/perl/edu/qanda/plqa00016/ #----------------------------------------------------------------------# # FUNCTION: hashValueAscendingNum # # # # PURPOSE: Help sort a hash by the hash 'value', not the 'key'. # # Values are returned in ascending numeric order (lowest # # to highest). # #----------------------------------------------------------------------# sub hashValueAscendingNum { $HASH{$a} <=> $HASH{$b}; } #----------------------------------------------------------------------# # FUNCTION: hashValueDescendingNum # # # # PURPOSE: Help sort a hash by the hash 'value', not the 'key'. # # Values are returned in descending numeric order # # (highest to lowest). # #----------------------------------------------------------------------# sub hashValueDescendingNum { $HASH{$b} <=> $HASH{$a}; }