Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Multi-stage flip-flop?

by runrig (Abbot)
on Dec 12, 2014 at 23:57 UTC ( [id://1110228]=note: print w/replies, xml ) Need Help??


in reply to Re: Multi-stage flip-flop?
in thread Multi-stage flip-flop?

If you use closures, you can force a different internal state for each range operator, e.g.:
sub mkrange { my ($r1, $r2) = @_; return sub { /$r1/../$r2/ }; } my $range1 = mkrange(qr/FIRST/, qr/SECOND/); my $range2 = mkrange(qr/THIRD/, qr/FOURTH/); while (<DATA>) { if ( $range1->() ) { print "R1: $_"; } if ( $range2->() ) { print "R2: $_"; } } __END__ junk FIRST 1 2 3 SECOND junk THIRD 4 5 6 FOURTH junk

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-23 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found