Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Flip-flop reset?

by runrig (Abbot)
on May 31, 2007 at 23:12 UTC ( [id://618600]=note: print w/replies, xml ) Need Help??


in reply to Re: Flip-flop reset?
in thread Flip-flop reset?

I was recently wondering how to do this, and why a regular anonymous sub (w/o closures) wouldn't work. Then I found this node. Though my solution (before finding this) was to generate an anonymous sub using eval $string. E.g.
my $range_checker = eval 'sub { local $_ = shift; /foo/../bar/ }';
At first, your way seems a little too indirect and magical, but it makes perfect sense if you create a 'flip-flop generator':
sub mk_flip_flop { my ( $re1, $re2 ) = @_; sub { local $_ = shift; /$re1/../$re2/ } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found