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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:38:44+00:00 2026-06-15T20:38:44+00:00

I am parsing a very simple text file and manipulating it into an array.

  • 0

I am parsing a very simple text file and manipulating it into an array. In my last step of the program I am trying to search for a user given term. I have tried many things but cannot seem to get it to work, my I search for a term that I know for a fact is in the array it still does not find it. I have a hunch that the variables might get tinkered with sometime during the “split”, “chop”, and “sort” functions but I am not exactly sure.

print "\n";
print "Enter a term you would like to search for: \n";

my $element = <STDIN>;

$num = grep(/$element/,@final);

if($num > 0){
print ("Term: " . $element . " found " . $num . " times. \n");
}else{
print "Not found. \n";
}

So I know for a fact that the term “apple” is in the list, when I search the term “apple” it prints that it was not found. Help please!!

  • 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-15T20:38:45+00:00Added an answer on June 15, 2026 at 8:38 pm

    You should try

    chomp(my $element = <STDIN>);
    

    Because your standard input will have a trailing newline that otherwise gets matched in your search. E.g.:

    $element = "foo\n";   
    grep /$element/, "foo bar";  # will not match
    

    You should also be aware that meta characters will be interpreted in your input. So for example, foo? will be considered “fo followed by an optional o”. To avoid that you can use quotemeta or \Q ... \E, e.g. in your regex use:

    /\Q$element\E/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple text file parsing app which searches for an email
I'm trying to get the basic of Treetop parsing. Here's a very simple bit
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I've got a very long text file as a result of a test last
I'm parsing a very simple XML schema with a SAX parser in Android. An
I am trying to do some html parsing. I am dealing with some very
First some background. I'm parsing a simple file format, and wish to re-use the
I'm experimenting with Trifecta for parsing a very simple functional language with Haskell-like layout
Zend Framework 1 had a very simple way of parsing URL routes and setting

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.