in reply to Converting to boolean

Nobody's mentioned $x != 0, which might be expected to work, but gets tripped up by the "0 but true" phenomenon, as does $x ^ ''. $x xor 0 should work, because xor is a logical op.

Disclaimer: I've only got perl4 to test on.


We're not really tightening our belts, it just feels that way because we're getting fatter.

Replies are listed 'Best First'.
Re^2: Converting to boolean
by tilly (Archbishop) on Jun 18, 2004 at 18:38 UTC
    Incidental trick, there is not need to use "0 but true" since "0.0" has the exact same effect. (Note that the quotes matter.)

    I'm not sure how that would run under flea-bitten corpses of dead camels though. (Can you tell that I'm somewhat flabbergasted at your using a version of Perl that is about a decade out of date?)
      Rest assured that I don't normally live in such third-world Perl environs. I'm only here for a week, and it hasn't been until today that I've needed Perl, so it hasn't been as horrible as it sounded.

      We're not really tightening our belts, it just feels that way because we're getting fatter.