in reply to Array Element Occurence
my $recordfile = "/foo/bar/copy.txt"; my %record; open (FILE, "$recordfile") or die "Can't open $recordfile: $!\n"; while(<FILE>) { if (/^(..)/) { $record{$1}++; } } print "The Total number or records = $.\n\n"; for (sort keys %record) { print "$_ reports $record{$_} records.\n"; } ## Or, to output the records from fewest to most: for (sort {$record{$a} <=> $record{$b} or $a cmp $b} keys %record) { print "$_ reports $record{$_} records.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array Element Occurence
by entr00pi (Scribe) on Sep 12, 2000 at 20:09 UTC | |
by ncw (Friar) on Sep 12, 2000 at 22:52 UTC |