in reply to Counting lines by content
I think the easiest way would be to use a hash - something like this?
Oops - just realised this doesn't handle the case where the 3rd field is a duplicate - in fact it doesn't worry about the 3rd field at all. guha has supplied some modifed code, which I've used to replace my slightly dodgy stuff!
#!perl use strict; use warnings; use diagnostics; my ($type, $desc, %fruit); open (FH, "y") || die "Cannot find file"; while (<FH>) { (undef, $type, $desc) = split /:/; $fruit{$type}{$desc}++; } close FH; foreach my $type (keys(%fruit)) { print "$type : ",scalar keys %{ $fruit{$type} }, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Counting lines by content
by l2kashe (Deacon) on Oct 09, 2002 at 13:47 UTC |