my %largest; while (<>) { my ($item, $group_id, $count) = split; next if $largest{$group_id} && $largest{$group_id}[2] >= $count; $largest{$group_id} = [ $item, $group_id, $count, $_ ]; } for (values(%largest)) { print($_->[-1]); }
Keeps first on ties.
Update: Added note at bottom.
In reply to Re: Retrieving data with largest count
by ikegami
in thread Retrieving data with largest count
by Angharad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |