Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Perl reading in a file and getting a string in between two strings on different lines

by Anonymous Monk
on Apr 17, 2017 at 21:23 UTC ( [id://1188174]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl reading in a file and getting a string in between two strings on different lines
in thread Perl reading in a file and getting a string in between two strings on different lines

my $beginString = "SEARCH"; my $endString = "TEST"; my $fileContent; open(my $fileHandler, $inputFile) or die "no read '$inputFile' $!\n"; while (<$fileHandler>) { print if /$beginString/ .. /$endString/; } close $fileHandler;
  • Comment on Re^2: Perl reading in a file and getting a string in between two strings on different lines
  • Download Code

Replies are listed 'Best First'.
Re^3: Perl reading in a file and getting a string in between two strings on different lines
by victorz22 (Sexton) on Apr 17, 2017 at 21:32 UTC

    That didn't work the output i got was just the whole file, i even tried to put an 's' at the end of it for many lines but that didn't work either.

      Show input that doesn't work! See SSCCE

      That's a classic, most likely you are doing it wrong.

      The only possibility top make it foolproof is to quote regex metacharacters and to anchor the line's start with ^

      print if /^\Q$beginString/ .. /^\Q$endString/;

      See quotemeta

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found