This appears to meet your spec:
#!/usr/bin/perl
use strict;
use warnings;
use 5.10.0;
use Data::Dumper;
my $beginString = "SEARCH";
my $endString = "TEST";
my $fileContent;
{
local $/;
$fileContent = <DATA>;
}
if($fileContent =~ /\b$beginString\b(.*?)\b$endString\b/s){
my $result = $1;
print $result;
}
#print Dumper($fileContent);
__DATA__
#Ignoring this
SEARCH =>
#Beginning of data I need
.......
........
#all the data I need
.......
.....
#End of Data I Need
TEST =>
# And ignoring this
Given that it's largely taken from your posted code, I wonder if you accidentally fixed your issue in preparing the post. If this does not output what you need, please describe how.
Sidenote 1:
my $fileContent;
open(my $fileHandler, $inputFile) or die "Could not open file '$inputF
+ile' $!";
{
local $/;
$fileContent = <$fileHandler>;
}
close($fileHandler);
You can rewrite this as
my $fileContent = do {
open(my $fileHandler, $inputFile) or die "Could not open file '$in
+putFile' $!";
local $/;
<$fileHandler>;
};
and avoid scoping challenges on that file handle.
Sidenote 2:
When using start/finish tags, assuming you want literals, you should quotemeta:
if($fileContent =~ /\b\Q$beginString\E\b(.*?)\b\Q$endString\E\b/s){
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.