sub sorthasharray($$) { # takes reference to array of hashes, and array of key names to sort by. my ($hasharray, $keylist) = @_; my $keyCount; # counter my $hashCount; # counter for $hashCount ( 0 .. $#$hasharray ) { # walk through the array for $keyCount ( 0 .. $#$keylist ) { # walk through the keys if ( $$hasharray[$hashCount]{$$keylist[$keyCount]} =~ /^\d*?\.??\d*?$/ ) { # check to see if this should be a numeric comparison my $zeros = 12 - (length($$hasharray[$hashCount]{$$keylist[$keyCount]})); # find out how many zeros we need #to pad to the right to make a string comparison equivalent to a numeric comparison #(this isn't onehundred percent accurate, especially for float numbers. Anyone want to take a crack at it? for $zeroCount ( 1 .. $zeros ) { $$hasharray[$hashCount]{sortkey} .= "0"; # padd the zeros } } $$hasharray[$hashCount]{sortkey} .= $$hasharray[$hashCount]{$$keylist[$keyCount]}; # build sortkey by concatenating all sort keys in order } } @$hasharray = sort { $$a{sortkey} cmp $$b{sortkey} } @$hasharray; # do the sort for $hashCount ( 0 .. @$hasharray ) { delete $$hasharray[$hashCount]{sortkey}; # delete the unneeded key from all the hashes } }