derpp has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
I've been posting tons of questions, and thanks for all the replies. I'm sucha nublet at this. But anyway, here's my problem: I can successfully get my program to count the number of occurences, but for some reason, certain words, like 'The' and other commonly used words are reappearing, even though they had been counted already. My only guess is that Perl's reading it in paragraphs?The website I copied my words from is http://money.cnn.com/2010/08/10/news/companies/walt_disney_earnings/index.htm . the third, fourth, fifth, and sixth paragraph. Just put it in a word document and open it up.
Sorry. I know this is really troublesome.use warnings; open (FILE, '<insertfilepath>' || $!); undef($/); while (<FILE>) { @array = split(/\ /, $_); my $word; foreach (@array) { print "$_\n"; } } for (@array){ s/[\,|\.|\!|\?|\:|\;|\"|\'|\<|\>]//g; $word{$_}++; } for (sort(keys %word)) { print "$_ occurred $word{$_} times\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: counting number of occurrences of words in a file
by ikegami (Patriarch) on Aug 11, 2010 at 18:26 UTC | |
|
Re: counting number of occurrences of words in a file
by kennethk (Abbot) on Aug 11, 2010 at 18:32 UTC | |
by derpp (Acolyte) on Aug 11, 2010 at 19:01 UTC | |
by toolic (Bishop) on Aug 11, 2010 at 19:17 UTC | |
by ssandv (Hermit) on Aug 11, 2010 at 19:41 UTC | |
by kennethk (Abbot) on Aug 11, 2010 at 19:08 UTC | |
by ww (Archbishop) on Aug 11, 2010 at 20:20 UTC | |
by graff (Chancellor) on Aug 12, 2010 at 02:11 UTC |