But this doesn't remove the words. What's wrong?
Two things.
First, look closely at line 65
You are not adding to @words but overwriting it for each line of <IN>.
This is easy to fix, just use push like this:
push @words,split(/\W/, $_);
Second, look at your loop labelled OUTER.
You loop through the list of banned words, and for each banned word you check to see if it is equal to the candidate word. If not, you accept it into %count.
This means you even though a word might be on the banned list, you will accept it into %count many times before finally "rejecting" it.
The fix is simple. Replace lines 69 to 77 with
$count{$word}++ unless exists $banned{lc $word};
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.