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.