#!perl -w die "usage: flatten \n" unless (@ARGV == 1); $file = shift; open(FILE, "<$file") or die "can't open file '$file': $!\n"; while () { @words = split(/\W+/); foreach $word (@words) { next if (length($word) < 4); next if ($word =~ /^[A-Z_]+$/); $word =~ tr/A-Z/a-z/; $count{$word}++; } } close(FILE); foreach $word (sort mysort keys(%count)) { printf("%-40s : %6d\n", $word, $count{$word}); } sub mysort { my($aa,$bb) = ($count{$a},$count{$b}); if ($aa == $bb) { return( $a cmp $b ); } else { return( $bb <=> $aa ); } }