Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 exploiting the Monastery: (1)
As of 2022-05-18 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?