in reply to Re: require problems
in thread require problems

When I'm feeling particularly evil, I'll use:
2;
or
"any true value will do";
or even
"0 but true";
Trivia question: why is the string "0 but true" special, and what's special about it?

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: Re: require problems
by chromatic (Archbishop) on Sep 19, 2000 at 21:40 UTC
    Well, it's true in Boolean context but 0 in numeric context. Looking through the docs on fcntl, it looks like it's useful for the Perl calls that are wrappers to C system calls.

    For example, if fcntl returns -1 to signify failure, Perl will massage that into undef. If it returns 0, Perl will use "0 but true" -- which means you can use it either numerically (C-style, expecting 0 to correspond to success) or Booleanifically (Perl-style, expecting 'true' to mean success).

    Close enough?

      But what is really special about "0 but true" is that it becomes 0 in a numeric context without a warning.

              - tye (but my friends call me "Tye")
        But what is really special about "0 but true" is that it becomes 0 in a numeric context without a warning.
        ding ding ding ding, that's what I was looking for!

        And now for trivia question 2, "why is this so?"

        -- Randal L. Schwartz, Perl hacker

        Ahh - but it wasn't *in* numeric context....
RE: RE: Re: require problems
by Shendal (Hermit) on Sep 19, 2000 at 21:53 UTC

      Heheh, you're on to something...

      How about the age old paradox:

      "This statement is false.";
RE: RE: Re: require problems
by Anonymous Monk on Sep 20, 2000 at 01:43 UTC
    my $true = "0 but true"; print "$true\n" if $true == 0;
RE: RE: Re: require problems
by Zarathustra (Beadle) on Sep 19, 2000 at 21:53 UTC

    Or perhaps even more devilish:

    # return true 0 . 0;
RE: RE: Re: require problems
by Zarathustra (Beadle) on Sep 19, 2000 at 21:47 UTC

    Well, I fail to see how the string "0 but true" is any more special than "any true value will do".

    They're both simply strings that interpolate in a boolean context to true

    how about:

    0 . "true";

    for something ever so slightly more "evil"...

    (c8=

      Well, I fail to see how the string "0 but true" is any more special than "any true value will do".
      Your failure to see it doesn't mean it's not more special. See other posts in this thread.

      Hint: turn on warnings.

      -- Randal L. Schwartz, Perl hacker

RE: RE: Re: require problems
by extremely (Priest) on Sep 20, 2000 at 04:58 UTC

    My current fave is:

    # grr... "Why should version 5.6 make me do this in a module?"

    Of course I like the capital letter "O"; too =)

    --
    $you = new YOU;
    honk() if $you->love(perl)