in reply to Retrieving data with largest count
Please post your code the next time, often a few small changes suffice to make such a program work.
... my %best; while (my $line=<YOURFILE>) { chomp $line; my ($item,$group,count)= split(/\s+/,$line); if ((not exists $best{$group}) or $best{$group}{count}<$count) { $best{$group}{count}=$count; $best{$group}{item}= $item; } } #to print them out foreach my $group ( keys %best) { print "$best{$group}{item} $group $best{$group}{count}\n"; }
PS: You didn't specify what should happen when two items in a group have the same count.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Retrieving data with largest count
by Angharad (Pilgrim) on Jun 02, 2009 at 15:15 UTC | |
by GrandFather (Saint) on Jun 04, 2009 at 20:27 UTC |