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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.