I have a hash (in Perl) where the values are all numbers. I need to create another hash containing all key / value pairs from the first hash, where the value is the maximum for all values.
For example, given
my %hash = (
key1 => 2,
key2 => 6,
key3 => 6,
);
I would like to create a new hash containing:
%hash_max = (
key2 => 6,
key3 => 6,
);
I'm sure there are many ways to do this, but I'm looking for an elegant solution (and the opportunity to learn!).
source
share