in reply to Re: max key-value pair in a hash
in thread max key-value pair in a hash

For some reason, each strikes me as a slightly more natural way to do this. If nothing else, it avoids the construction of the key list.

my %h = ( sunny => 0.063, cloudy => 0.017, rainy => 0.020, hellish => 0.103, ); my( $max_key, $max_val ) = each %h; while ( my($k,$v) = each %h ) { $v > $max_val and ($max_key,$max_val) = ($k,$v); } print "$max_key => $max_val\n";
We're building the house of the future together.