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"; }
In reply to counting number of occurrences of words in a file by derpp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |