in reply to tutelage needed
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: tutelage needed
by ctp (Beadle) on Jan 01, 2004 at 02:54 UTC | |
by jweed (Chaplain) on Jan 01, 2004 at 03:00 UTC | |
by ctp (Beadle) on Jan 01, 2004 at 03:19 UTC | |
by jweed (Chaplain) on Jan 01, 2004 at 07:22 UTC | |
by ctp (Beadle) on Jan 04, 2004 at 05:09 UTC |