Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Print multiple lines based on condition

by BillKSmith (Monsignor)
on Mar 13, 2020 at 15:04 UTC ( [id://11114226]=note: print w/replies, xml ) Need Help??


in reply to Print multiple lines based on condition

This code is a variation of the state-machine concept. The variable '$out' is a reference to the file handle of the current output file. When a 'command' line is discovered, the last hex digit of the address field is extracted. The "state" is set to one reference or the other depending on whether or not it is an even digit.
my $out; while (<INFILE>) { if(/addr:0x[0-9a-f]+([0-9a-f])/) { $out = ($1 =~ /[02468ace]/)? $OUT_FILE0 : $OUT_FILE1; } print {$out} $_; }
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-23 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found