in reply to Booleans from flip-flops

IIRC (returned) boolean values in perl are either 1 or undef
Perl doesn't have "booleans". Function may return true or false values - it's not always defined which true or false value they return. The empty string is also often returned as a false value, and sometimes "0 but true" is returned. Or "0E0".

The manual page says:

The right operand is not evaluated while the operator is in the "false" state, and the left operand is not evaluated while the operator is in the "true" state. The precedence is a little lower than || and &&. The value returned is either the empty string for false, or a sequence number (beginning with 1) for true. The sequence number is reset for each range encountered. The final sequence number in a range has the string "E0" appended to it, which doesn’t affect its numeric value, but gives you something to search for if you want to exclude the endpoint. You can exclude the beginning point by waiting for the sequence number to be greater than 1.
Which explains it.

Replies are listed 'Best First'.
Re^2: Booleans from flip-flops
by LanX (Saint) on Jan 20, 2010 at 18:17 UTC
    Right it's normally empty not undef ...

    Thanks, I've mysteriously overlooked the second paragraph in perlop only seeking for 1E0...

    Anyway the wording "it returns a boolean value" is somehow misleading ...

    Cheers Rolf

      It's not an empty string, but a dualvar that has zero is the numeric slot and an empty string in the string slot.
      $ perl -wle'print ""' $ perl -wle'print 0+""' Argument "" isn't numeric in addition (+) at -e line 1. 0 $ perl -wle'print !1' $ perl -wle'print 0+!1' 0

      Anyway the wording "it returns a boolean value" is somehow misleading ...

      It does return something that's a boolean value (true when there's a match, false when there's no match). It also returns ...

        Fascinating, I never heard about dualvars nor that scalars have slots...

        Seems only to be explained in Scalar::Util

        Cheers Rolf