Hi everyone! Now I have extracted all sentences from htmls to Quotes.txt successfully. My next step is to remove all stopwords (using stopwords.txt) from the quotes.txt, and then count the number of occurrences each word appears and output this list to a text file with the most frequent words appearing at the top of the file. Now I am confused how to remove stopwords./p>

my $quotes="Quotes.txt"; open(OUTPUT, ">$quotes")||die("Could not open $quotes!"); my $page_num=1; while ($page_num<=10){ my $htmlpages="Page$page_num.html"; open (INPUT,"$htmlpages")||die("Could not open $htmlpages"); my $line=""; while ($line=<INPUT>){ if($line=~m/<span class="text" itemprop="text">(.+?)<\/span/ig){ my $quotes=$1; $quotes =~ s/I'm/I am/ig; $quotes =~ s/(\w+?)'re/$1 are/ig; $quotes =~ s/(\w+?)'s/$1 is/ig; $quotes =~ s/(\w+?)n't/$1 not/ig; $quotes =~ s/it's/it is/ig; $quotes =~ s/(\w+?)'ll/$1 will/ig; $quotes =~ s/I've/I have/ig; $quotes =~ s/won't/will not/ig; $quotes =~ s/can't/cannot/ig; $quotes =~ s/\&\#34;/'/ig; $quotes =~ s/\&\#39;/'/ig; $quotes =~ s/let's/let us/ig; $quotes =~ s/lady's/lady is/ig; print OUTPUT "$quotes\n"; } } $page_num=$page_num+1; close(INPUT); } close(OUTPUT); my $quotes_0="WordCount.txt"; my $quotes_1="Quotes.txt"; open(QUOTES,">$quotes_0")||die("Could not open $quotes_0"); my $stopwords="stopwords.txt"; open(WORDS,"$stopwords")||die("Could not open $stopwords"); open(OLD,"$quotes_1")||die("Could not open $quotes_1"); my $line1=""; while(my $stop=<WORDS>){ if($stop=~m/(.+?)/ig){ my $stopwords=$1; if ($line1=<OLD>){ if($line1=~s/\b($stopwords)\b//ig){ print QUOTES "$line1\n"; } } } } close(WORDS); close(OLD); close(QUOTES);

In reply to How Could I Remove Stopwords using stopwords.txt? by mynameisbob

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.