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

Re: saving matching pattern with flip-flop operator

by bart (Canon)
on Jun 23, 2011 at 10:54 UTC ( #911055=note: print w/replies, xml ) Need Help??


in reply to saving matching pattern with flip-flop operator

You could use $1, but I expect problems with retained old values if the regex didn't match.

So I prefer to directly, explicitly capture the captured value. Like this:

while (<>) { if(/START/ ... (my($time) = /END TIME (.+)/)) { unless(defined $time) { next if /START/ || /^\s*$/; print; } else { print "End time at $time\n"; } } }
BTW | is for bitwise or; you (ought to) want either or or ||.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-09-25 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?