I'm pulling the most commonly used words out of a text file and putting them in another, but I don't want any a or an or the etc. in it. Here's what I got:
#!/usr/bin/perl for($i=1; $i<20000; $i++) { open(IN,"/var/www/data/$i.txt") || die $!; my $url = <IN>; my %banned = ( "a" => undef, "at" => undef, "be" => undef, "for" => undef, "and" => undef, "to" => undef, "of" => undef, "in" => undef, "the" => undef, "as" => undef, "i" => undef, "it" => undef, "are" => undef, "is" => undef, "am" => undef, "on" => undef, "an" => undef, "you" => undef, "me" => undef, "b" => undef, "c" => undef, "d" => undef, "e" => undef, "f" => undef, "g" => undef, "h" => undef, "j" => undef, "k" => undef, "l" => undef, "m" => undef, "n" => undef, "o" => undef, "p" => undef, "q" => undef, "r" => undef, "s" => undef, "t" => undef, "u" => undef, "v" => undef, "w" => undef, "x" => undef, "y" => undef, "z" => undef, "0" => undef, "1" => undef, "2" => undef, "3" => undef, "4" => undef, "5" => undef, "6" => undef, "7" => undef, "8" => undef, "9" => undef, "10" => undef, ); while(<IN>){ chomp; @words = split(/\W/, $_); } close(IN); foreach $word (@words) { $word=lc($word); OUTER: while( ( $key, $value) = each %banned ) { if($key eq $word) { $word = ""; last OUTER; } else { $count{$word}++ unless $word eq ""; } } } @keys = reverse sort { $count{$a} <=> $count{$b} } keys %count; @keys = splice(@keys,0,50); print "File: $i\n"; open(FILE,">/var/www/sorted/$i.txt") || die $!; print FILE "$url\n"; print FILE join("\n", @keys); close(FILE); $string = ""; %count = (); }
But this doesn't remove the words. What's wrong?

Thanks


In reply to Removing common words by mkurtis

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.