Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: Getting next line after matched one

by state-o-dis-array (Hermit)
on Dec 30, 2004 at 21:00 UTC ( #418401=note: print w/replies, xml ) Need Help??

in reply to Re^2: Getting next line after matched one
in thread Getting next line after matched one

The previous posts do go to the next line, the flag is set so that when you get to the next line, you know that the previous line was a match. If you get to a line, and the flag is set, then do whatever it is that you wanted to do after finding the matching line.
I'm going to use tremmel's code to make sure that you understand what is going on, forgive me if I go in to too much detail, but I don't know where your level of understanding is - not trying to talk down to you, I'm a relative beginner myself.
my $flag = 0; while (<FILE>) { #If not at end of file process next line if ($flag) { #flag is set, previous line was a match $flag = 0; #reset the flag do_something($_); #do what you want to do after finding match } if (/pattern/) { #if this line matches $flag = 1; #set the flag so I can do something on next line next; #go to next line, not required but might make more read +able } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://418401]
[Corion]: AltSpace VR is amazingly good - highly polished and with some of the games you get for free what you'd pay EUR 20 or EUR 40 otherwise
[Corion]: But maybe it's also due to that I play with friends, which makes a game more enjoyable anyway ;)
[Corion]: Oh - I released a new version of some module, thanks to a pull request. But I don't consider "update Makefile.PL" and "update author tests" as "writing code" ;-D
[marto]: sounds fun, the opposite of my weekend :P
[Corion]: marto: You wrote Perl? Or did you have to work (and wrote Perl)?

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-08-21 09:28 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (319 votes). Check out past polls.