Okay, a couple of things:

1 - Do you expect your file to be one long line? If not, you need to "slurp" the file, rather than doing what you're doing now (reading only the first line). Try $big_string = do {local $/; <TEXTFILE>};.

2 - Your first substitution statement does not require the outside capturing parens. It's just noisy.

3 - I wouldn't sort the array before doing the frequency count, as it just takes time for little gain.

4 - Finally, in response to your last question as to how to actually do the count, I have a few suggestions. An idiom that is useful is, for each item to say $hash{$word}++. It creates an entry if the word has not been seen before, and increments it if has. Use a for loop or a map statement to construct the hash. In the end, use a sort with a routine which sorts by the entries in the hash and (optionally) afterwards ascii-betically by the actual words.


Hope that helped!



Who is Kayser Söze?
Code is (almost) always untested.

In reply to Re: tutelage needed by jweed
in thread tutelage needed by ctp

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.