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; }
|
|---|
| 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 |