Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8810257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:05:13+00:00 2026-06-14T03:05:13+00:00

I have read so many forms on how to remove stop words from files,

  • 0

I have read so many forms on how to remove stop words from files, my code remove many other things but I want to include also stop words. This is how far I reached, but I don’t know what I am missing. Please Advice

use Lingua::StopWords qw(getStopWords);
my $stopwords = getStopWords('en');

chdir("c:/perl/input");
@files = <*>;

foreach $file (@files) 
  {
    open (input, $file);

    while (<input>) 
      {
        open (output,">>c:/perl/normalized/".$file);
    chomp;
    #####What should I write here to remove the stop words#####
    $_ =~s/<[^>]*>//g;
    $_ =~ s/\s\.//g;
    $_ =~ s/[[:punct:]]\.//g;
    if($_ =~ m/(\w{4,})\./)
    {
    $_ =~ s/\.//g;
    }
    $_ =~ s/^\.//g;
    $_ =~ s/,/' '/g;
    $_ =~ s/\(||\)||\\||\/||-||\'//g;

    print output "$_\n";

      }
   }

close (input);
close (output);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:05:14+00:00Added an answer on June 14, 2026 at 3:05 am
    # Always use these in your Perl programs.
    use strict;
    use warnings;
    
    use File::Basename qw(basename);
    use Lingua::StopWords qw(getStopWords);
    
    # It's often better to build scripts that take their input
    # and output locations as command-line arguments rather than
    # being hard-coded in the program.
    my $input_dir   = shift @ARGV;
    my $output_dir  = shift @ARGV;
    my @input_files = glob "$input_dir/*";
    
    # Convert the hash ref of stop words to a regular array.
    # Also quote any regex characters in the stop words.
    my @stop_words  = map quotemeta, keys %{getStopWords('en')};
    
    for my $infile (@input_files){
        # Open both input and output files at the outset.
        # Your posted code reopened the output file for each line of input.
        my $fname   = basename $infile;
        my $outfile = "$output_dir/$fname";
        open(my $fh_in,  '<', $infile)  or die "$!: $infile";
        open(my $fh_out, '>', $outfile) or die "$!: $outfile";
    
        # Process the data: you need to iterate over all stop words
        # for each line of input.
        while (my $line = <$fh_in>){
            $line =~ s/\b$_\b//ig for @stop_words;
            print $fh_out $line;
        }
    
        # Close the files within the processing loop, not outside of it.
        close $fh_in;
        close $fh_out;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Windows Forms and Navigation I have researched and read many different web articles and
I have read many question about improving the performance of C++ and C code
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I have many forms which has many text input that are read-only. I am
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read many answers regarding this still i am getting confused if i
I have read many fine algorithms for identifying the most significant bit for 32-
I am trying understand ViewModels deeper and I have read many articles and blogs
Am tearing my hair out here. Have read many examples which describe how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.