Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by victorz22 (Sexton)
on Apr 17, 2017 at 22:46 UTC ( [id://1188181]=note: print w/replies, xml ) Need Help??


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

Thanks For the help but the ou put was the same. The script failed to ignore everything before the $beginString and it succeeded in removing everything after the $endString. Both of these strings are indented so i am wondering if the blank space is getting in the way of matching the string. Here is what the output looks like and my new code after the recommended modifications.

The failed output looks like this ........... #data i want ignored, that the program fails to remove ........... ........... SEARCH => #Beginning of data I need .......... .......... .......... #End of data I need, The program successfully removes +the data below this line TEST =>
my $beginString = "SEARCH"; my $endString = "TEST"; my $fileContent = do { open(my $fileHandle, $inputFile) or die "Could not open file '$inp +utFile' $!"; local $/; <$fileHandle>; }; if($fileContent =~ /\b\Q$beginString\E\b(.*?)\b\Q$endString\E\b/s){ my $result = $1; print $result; }
  • Comment on Re: Perl reading in a file and getting a string in between two strings on different lines
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Perl reading in a file and getting a string in between two strings on different lines
by NetWallah (Canon) on Apr 17, 2017 at 23:06 UTC
    Both kennethk's code and your code work correctly for me, truncating the top and bottom parts, with indentation.

    Perhaps the code you are editing may not be the same as the one you are running ???....

            ...Disinformation is not as good as datinformation.               Don't document the program; program the document.

Log In?
Username:
Password:

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

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

    No recent polls found