Jun 13
2002

wordcount.pl

Gracias, Andrew McNaughton! (via Sigia-l)

----- wordcount.pl -------
#!/usr/bin/perl
use strict;

#count words from stdin
my %count;
while (<>) {
my @words = m/([a-z][a-z']*[a-z]|[a-z])/ig;
foreach my $word (@words) {
$count{lc $word}++;
}
}

# list frequencies to stdout
foreach my $word (sort {$count{$b} <=>
$count{$a}} keys %count) {
print "$word: $count{$word}\n";
}

--------------------------

Comments & TrackBacks

Comments and trackbacks are closed.

A Few Related Entries

Share