Friday, January 27, 2006

Frequency counts

while(<>) {
tr/A-Z/a-z/; # convert to lower case
tr/.,:;!?"(){}//d; # strip out punctuation
foreach $word (split) { # split line into words
$count{$word}++; # count words, put count into hash (word is key, count is value)


foreach $word (sort keys %count) { # sort hash by the value of the key
print "$word $count{$word}\n"; # print out the hash in key order


No comments: