in reply to Re^3: Multi-stage flip-flop? ( till() - proof of concept)
in thread Multi-stage flip-flop?

The CODE part shouldn't work left from a fat comma.

Keys are always a stringifyed!

Cheers Rolf

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

  • Comment on Re^4: Multi-stage flip-flop? ( till() - proof of concept)

Replies are listed 'Best First'.
Re^5: Multi-stage flip-flop? ( till() - proof of concept)
by RonW (Parson) on Dec 12, 2014 at 19:38 UTC

    I added a "code ref" test:

    sub c3 { print "Evaluating condition 3\n"; /gamma/; } while (<DATA>) { chomp; mff(qr/alpha/ => \&s1, qr/beta/ => \&s2, \&c3 => \&s3, qr/omega/ ) or print "*:$_\n"; }

    The output:

    *:This is 1:the alpha 1:but not 1:the omega 2:Now the beta Evaluating condition 3 2:progressing to Evaluating condition 3 3:the gamma 3:and finally *:the omega *:Did this work?

    Which is what I expected.

    Apparently, the "fat comma" ( => ) only quotes bare words. chromatic claims the same in the first paragraph of http://www.modernperlbooks.com/mt/2013/04/the-fat-comma-and-clarity.html.

    So, => is not imposing string context on \&c3 so that doesn't get stringified.

      ah yes right!

      The trap was that hash keys are always strings, but while the arguments look like a hash structure they aren't real keys and values.

      I remember now that I fell into this trap before...

      But still, when passing values which are supposed to be boolean it's safer to negate them.

      Cheers Rolf

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

        Yes, my scalar test didn't work. See node Re^4: Multi-stage flip-flop? ( till() - proof of concept)

        But then I changed the test:

        while (<DATA>) { chomp; mff(qr/alpha/ => \&s1, qr/beta/ => \&s2, \&c3 => \&s3, !!c4() ) or print "*:$_\n"; }

        which imposes scalar context on the call to c4, so it worked correctly:

        Evaluating condition 4 *:This is Evaluating condition 4 1:the alpha Evaluating condition 4 1:but not Evaluating condition 4 1:the omega Evaluating condition 4 2:Now the beta Evaluating condition 4 Evaluating condition 3 2:progressing to Evaluating condition 4 Evaluating condition 3 3:the gamma Evaluating condition 4 3:and finally Evaluating condition 4 *:the omega Evaluating condition 4 *:Did this work?

        Clearly should be mentioned in the documentation for any future version of mff.