Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Extract Block Of Text From Log

by davido (Cardinal)
on Nov 20, 2018 at 22:29 UTC ( #1226082=note: print w/replies, xml ) Need Help??


in reply to Extract Block Of Text From Log

You're almost there. If you intend to read record by record, but then use the flip-flop operator as though it's operating line by line, you'll have to modify your code's flow a little:

local $/ = 'END OF REPORT'; while (<DATA>) { foreach my $line (split /\n/) { print "$line\n" if $line =~ /\*\sparameters after change\s=\*/ + .. $line =~ /\*\sNRG location\s=/; } }

But it might be easier to keep the existing "record" file read, and then treat the record as a multi-line string (since it is):

local $/ = 'END OF REPORT'; while (<DATA>) { print "$1\n" if m/(^\*+\sparameters after change\s=\*+\n.+?^\*+\sN +RG location\s=\*+$)/ms; }

Another strategy could be going back to using the flip-flop operator, but reading your file line by line, though doing so means you'll have to take care to check that you haven't included a record termination line within the truthy state of the flip-flops, as that would indicate that your record ended prematurely or was otherwise poorly formed.


Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2019-05-21 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (132 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!