I’m having some trouble sorting through and extracting multiple lines of text. Here’s my code:
my $searched = $doc->content;
if($searched =~ /MODIFIED files in Task $_[1] : (.*?) The/gs){
print $1,"\n";
$Modified = $1;
}
if($searched =~ m/COMPILED in Task $_[1] : (.*?) The/ms){
$Compiled = $1;
}
if($searched =~ m/DELETED in Task $_[1] : (.*?) Comments/ms){
$Deleted = $1;
}
Here’s is a example of the text file:
The following are the MODIFIED files in Task 50104 : **Directory Filename Version --------- -------- ------- Something Something ..... ...... ...... ..... ....... ........ .....** The following are the files to be COMPILED in Task 50104 : **Directory Filename --------- -------- ......... .........** The following are the files to be DELETED in Task 50104 : **Directory Filename --------- --------** Comments: Blah blah.......
Where the text in between the ** is what I want to extract. Sorry about the poor formatting
I am not sure that your text contains spaces around
:and before The/Comments (in fact, it seems to me that:is followed by newline, andTheis preceded by newline, not space); instead of using:try using:
I also don’t think you need the /g or /m switch…
If this does not work, I would suggest refining your regex in steps, i.e., first ensure that
/MODIFIED files in Task $_[1] :matches up to the:then add the rest.