Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: Multi-stage flip-flop?

by RonW (Parson)
on Dec 11, 2014 at 17:23 UTC ( [id://1110074]=note: print w/replies, xml ) Need Help??


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

How else would till control which condition got evaluated?

If till were actually built in to Perl, it could control control evaluation.

But, if it was built in, then it could impose scalar context on the conditions with out needing the - in front.

Replies are listed 'Best First'.
Re^5: Multi-stage flip-flop?
by LanX (Saint) on Dec 11, 2014 at 18:46 UTC
    It doesn't need to know the condition just the result by position.

    I'll post some proof of concept later...

    Asking for built-ins is an illusion...

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      With .. the first condition is only evaluated when .. is in the "inactive" state. The second condition is only evaluated when .. is in the "active" state. And that is the behavior I am (implicitly) proposing - that only the condition corresponding to the current state be evaluated.

      So, an initial draft of till might be:

      sub till { my $state = lookupState(caller); croak('Fatal: till: Too few conditions for current state.') if ((2 * $state) >= @_); if ref($_[2 * $state]) eq 'SCALAR' { $state++ if ($_[2 * $state]); } elsif ref($_[2 * $state]) eq 'Regexp' { $state++ if (/$_[2 * $state]/); } elsif ref($_[2 * $state]) eq 'CODE' { $state++ if ($_[2 * $state]->($_)); } saveState($state, caller); if ((2 * $state) >= @_) { # final condition was true saveState(0, caller); return 0; } return 0 if ($state < 1); # init condition still false return $_[2 * ($state - 1)]->($_); }

      Note: The above actually behaves like ... in that only 1 condition is evaluated per invocation.

      Disclaimer: Not yet tested.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found