in reply to Re: String comparison "\x00" vs. "".
in thread String comparison "\x00" vs. "".

There are some exceptions to 1 above. If the character contained is numerically zero, then despite having length, the string will conditionally test as false.
...
And then there are (the celebrated) exceptions to the exception, like "0e0" (& "0e-0" & ... ) that the 'type safety' people hate, but that help make the world go around.
There are only exceptions to the exception because of you convoluted way of writing what is false. If you state it as:

An expression is false if it (in scalar context -- boolean context is scalar context) evaluates to any of the following:

No exceptions. No exceptions to exceptions. And it has nothing to do with types.

Update: if a variable has both string and numerical values, then the truth value of the string part wins:

use Scalar::Util 'dualvar'; my $p1 = dualvar 0, "foo"; # True my $p2 = dualvar 1, ""; # False

Replies are listed 'Best First'.
Re^3: String comparison "\x00" vs. "".
by ikegami (Patriarch) on Jun 08, 2010 at 15:41 UTC

    Overloaded bjects and tied variables can be false, and they're none of those.

    An expression is false if it stringifies to any of the following:

    • ""
    • "0"

    That includes undef and numerical zero. (It might fail for very tiny floats and weird dualvars, but it gives a good idea.)

      An expression is false if it stringifies to any of the following
      But it wouldn't be Perl if there wasn't an exception to that:
      use overload "bool" => sub {0}, '""' => sub {"Send in the clowns"}; my $o = bless []; # $o stringifies to "Send in the clowns" say "Hello" if $o; # No stringification happening here say "world" if "$o"; # Forced stringification
      prints just "world"
Re^3: String comparison "\x00" vs. "".
by BrowserUk (Patriarch) on Jun 08, 2010 at 11:39 UTC
    No exceptions. No exceptions to exceptions. And it has nothing to do with types.

    Utter ribald twaddle!

    I said: "There are some exceptions to 1 above.". And in that context, the rest of what I said is completely accurate.

    I didn't set out to define what is false, just answer the OPs question.

    If you follow a set of directions, but start at a completely different place, you will end up getting lost in your own confusion.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.