in reply to How to get the Max values' key!
Here is one way:
The code assumes that none of the second level hashes is empty, so the maximum always exists. If the maximum isn't unique (say if $r{123}{c} = 3 had also been given), a random key with the maximum value is selected.use List::Util qw( max); while ( my ( $first, $h) = each %r ) { my $second = { reverse %$h }->{ max values %$h}; print "\%r{$first}{$second} ==> $h->{ $second}\n"; }
The solution is inefficient if the second level hashes are big because for each of them the full inverted hash is built just to pick out a single value.
Anno
|
|---|