Here's somewhere to start. Completely untested code, I just threw this together in the reply textarea :). It may not work at all or it may have glitches. Give it a shot if you will, change whatever you may wish. I'd say that the definition of a "word" your regex uses could use some fixing.

my @banned = qw( a at be for and to of in the as i it are is am on an you me ); push( @banned, 0..10, 'a'..'z' ); my %banned; @banned{@banned} = undef; for my $file (0 .. 20000) { open( my $in, '<', '/var/www/data/' . $file . '.txt' ) or die "open failed: $!"; open( my $out, '>', '/var/www/sorted/' . $file . '.txt' ) or die "open failed: $!"; my %seen; while ( chomp( my $line = <$in> ) ) { for my $word ( split( /\W/, $line ) ) { $word = lc( $word ); ++$seen{$word} if ( exists( $banned{$word} ) ); } } my @frequent = ( sort { $seen{$b} <=> $seen{$a} } keys %seen )[0..50]; print $out join("\n", @frequent); close( $in ) or die "close failed: $!"; close( $out ) or die "close failed: $!"; }

In reply to Re: Removing common words by Anonymous Monk
in thread 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.