Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Matching consecutive "different" regex patterns across multiple lines

by duelafn (Vicar)
on Apr 23, 2011 at 13:04 UTC ( #900968=note: print w/replies, xml ) Need Help??


in reply to Re: Matching consecutive "different" regex patterns across multiple lines
in thread Matching consecutive "different" regex patterns across multiple lines

More explicitly, Anonymonk is suggesting processing the input line-by-line using something like the following rather than attempting to match a whole chunk at once. Here I am just keeping the john line. If you actually need the lines between, push them to a @buffer as Anonymonk suggests.

my $john; while (defined(local $_ = <DATA>)) { if (/^(john\d+)$/) { $john = $1; } elsif (/^(jacob \- \d\.0)$/) { if ($john) { print "$john - $1\n"; } else { die "Jacob is not preceded by John!"; } undef $john; } } __DATA__ bhgfsggdsgsg -- john1 weruwearnwrnweuarar jjafdaiuweifweofiuwe jacob - 1.0 -- nfaslf23523525 john2 asfsjldf43tgre john3 asbdfhskafbv3333v sdfahh34ttg sadfhk34t3wtg sdfhk3gfwghhw3 jacob - 2.0

Good Day,
    Dean

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://900968]
help
Chatterbox?
[marto]: I can relate to that somewhat, I'm a light sleeper and frequently get woken up by kids doing much the same as your cats
[jedikaiti]: Yea, the kids (& the cats) are good at that
talexb is having a hard time with Windows losing DNS info for Perlmonks when voting. CB works fine. Ugh.
[jedikaiti]: how odd

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2017-07-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (374 votes). Check out past polls.