A quick and simple way, especially if you don't want to read the whole file into memory first, would be:
s/([A-Z0-9]{5,})/$seenit{$1}++ or print "$1\n"/egi while <>;
Better yet, save the printing until the end, so you can sort the words alphabetically, or perhaps by the number of appearances:
s/([A-Z0-9]{5,})/$seenit{$1}++/egi while <>; ## Sorted by name for (sort keys %seenit) { print "$_: $seenit{$_}\n"; } ## Sorted by freuency, then by name: for (sort {$seenit{$a} <=> $seenit{$b} or $a cmp $b} keys %seenit) { print "$_: $seenit{$_}\n"; }
As a final suggestion, you may want to disregard the case of the words, in which case you'd want to use $seenit{lc $1}. Probably best, as words at the start of a sentence tend to be capitalized.
In reply to Re: Wordlist maker
by turnstep
in thread Wordlist maker
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |