Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Multi-stage flip-flop?

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


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

Almost. Your code is not qualifying the state before changing it.

Maybe like this:

my @fn = (\&doOtherProcessing, \&doStage1, \&doStage2, \&doStage3); my $fn = 0; while (<DATA>) { if ($fn == 0 and /for/) {$fn = 1} if ($fn == 1 and /their/) {$fn = 2} if ($fn == 2 and /fruit/) {$fn = 3} if ($fn == 3 and /lazy/) {$fn = 0} $fn[$fn]->($_); }

Replies are listed 'Best First'.
Re^3: Multi-stage flip-flop?
by roboticus (Chancellor) on Dec 11, 2014 at 12:53 UTC

    RonW:

    Good catch! I won't update my post, as you've already posted a suitable fix.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-25 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found