in reply to How to get the Max values' key!
It's not pretty, but it works
my %r; $r{123}{a}=3; $r{123}{b}=2; $r{456}{c}=5; $r{456}{d}=7; my %new_r = map { my $max_inner; for my $inner ( keys %{$r{$_}} ) { $max_inner = $inner if !defined $max_inner || $r{$_}{$inner} > $r{$_}{$max_inn +er}; } ( $_ => { $max_inner => $r{$_}{$max_inner} } ) } keys %r; print Dumper \%new_r; __END__ $VAR1 = { '123' => { 'a' => 3 }, '456' => { 'd' => 7 } };
If there's anything you don't understand, ask!
update: now returns a hash, as per OP's update
|
|---|