in reply to Re: Re: variable set to 0 ? 0 : 1
in thread variable set to 0 ? 0 : 1

How about
return $status && 1; # canonize false, leave true as-is
for completness sake.

update: I got that backwards. && returns the last part evaluated, and skips the right side if the left already determines the outcome. So, if $status is false it returns it unchanged; if true it evaluates the right hand side and gets a numeric 1. It canonizes true, leaves false as-is.

$status || 0; will return $status unchanged if true, and check the rhs if false. So that canonizes false and returns true unchanged.

Replies are listed 'Best First'.
Re: another variation (variable set to 0 ? 0 : 1)
by sauoq (Abbot) on Sep 07, 2002 at 04:51 UTC
    return $status && 1;  # canonize false, leave true as-is

    That would be great except it doesn't canonize false. It returns $status if $status is false. So, for example, if $status is "" it will return "", not 0.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: another variation (variable set to 0 ? 0 : 1)
by sauoq (Abbot) on Sep 10, 2002 at 00:17 UTC
    $status || 0;

    I'll agree that snippet "canonizes false" but it still isn't what the original did. The original canonized numerical equality with 0. The above snippet will return "foo" because "foo" is true. The original would have returned 0 because "foo" == 0 is true.

    OK, OK, OK. I'll just be getting on with my life now. :-)

    -sauoq
    "My two cents aren't worth a dime.";