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 7417761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:45:38+00:00 2026-05-29T07:45:38+00:00

So I have two files, one that contains my text, and another which I

  • 0

So I have two files, one that contains my text, and another which I want to contain filter words. The one shown here is supposed to be the one with the curse words. Basically, what I’m doing is iterating through each of the words in the text file, and trying to compare them against the curse words.

sub filter {
    $word_to_check = $_;

    open ( FILE2, $ARGV[1]) || die "Something went wrong. \n";

    while(<FILE2>) {
            @cursewords = split;
            foreach $curse (@cursewords) {
                    print $curse."\n";
                    if($word_to_check eq $curse) { return "BAD!";}
            }
    }
    close ( FILE2 );
}

Here are the “curse words”:

what is

Here is the text file:

hey dude what is up

But here’s what’s going wrong. As you can see, I’ve put a print statement to see if the curse words are getting checked correctly.

hey what
is
dude what
is
what what
is
is what
is
up what
is

I literally have no idea why this could be happening. Please let me know if I should post more code.

EDIT:

AHA! thanks evil otto. It seems I was getting confused with another print statement I had put in before. Now the problem remains: I think I’m not checking for string equality correctly. Here’s where filter is getting called:

    foreach $w( @text_file_words )
    {
            if(filter($w) eq "BAD!")
            {
                    #do something here
            }
            else { print "good!"; }
    }

EDIT 2: Nevermind, more stupidity on my part. I need to get some sleep, thanks evil otto.

  • 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-05-29T07:45:39+00:00Added an answer on May 29, 2026 at 7:45 am

    change

    $word_to_check = $_;
    

    to

    $word_to_check = shift;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to append two text files together. I have one file with a
I have 2 plain text files that contain some words, like: File 1 Aarhus
I have two very large(30000+ documents) collections, one contains words extracted from a text
I have the two following text files: First one: chr10 1000 1001 DEL 2.4807
What I'm trying to do: I have two files: One is the header.php which
i have two files one called stats.js one called storage.html in stats.js in contains
I have a text file words.txt that contains english words. Let's assume it contains
I have a text file that contains very long lines. I need one piece
I have two SSIS Solutions SolutionA Contains one utilities package that handles all emails
I have two text files bala.txt and bala1.txt bala.txt contains text line by line

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.