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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:27+00:00 2026-05-26T11:26:27+00:00

I am creating a perl script that takes in the a file (example ./prog

  • 0

I am creating a perl script that takes in the a file (example ./prog file)
I need to parse through the file and search for a string. This is what I thought would work, but it does not seem to work. The file is one work per line containing 50 lines

@array = < >;   
    print "Enter the word you what to match\n";
    chomp($match = <STDIN>);        

    foreach $line (@array){
        if($match eq $line){
            print "The word is a match";
            exit
        }
    }
  • 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-26T11:26:28+00:00Added an answer on May 26, 2026 at 11:26 am

    You’re chomping your user input, but not the lines from the file.

    They can’t match; one ends with \n the other does not. Getting rid of your chomp should solve the problem. (Or, adding a chomp($line) to your loop).

    $match = <STDIN>;
    

    or

    foreach $line (@array){
        chomp($line);
        if($match eq $line){
            print "The word is a match";
            exit;
        }
    }
    

    Edit in the hope that the OP notices his mistake from the comments below:

    Changing eq to == doesn’t “fix” anything; it breaks it. You need to use eq for string comparison. You need to do one of the above to fix your code.

    $a = "foo\n"; 
    $b = "bar"; 
    print "yup\n" if ($a == $b);
    

    Output:

    yup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PERL script that is creating a lot of sockets (around 700
I am newbie to Perl. I need to parse a tab separated text file.
I am creating a website that is using a perl script, PHP, a MySQL
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
I have a simple perl script that uses DBD::Oracle to run a query and
I have a need to upgrade a Perl CGI script where the users must
I have started creating a Perl package that contains a default email template. The
In Perl, is there any way to tell which .pl script has initialized this
Currently I am writing Perl script that creates LoadRunner scenario, execute the test, collect

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.