in reply to Re: Conditional style (if, &&) query
in thread Conditional style (if, &&) query

This comment is dead on, to extend the metaphor

# check for a pilot action if ($red_button_pressed) { eject_seat(); } eject_seat() if $massive_failure; # check for exceptional behavior # sub returns true/false if the seat was ejected return $red_button_pressed && $massive_failure && 1; # fixed to put th +e && 1 on the end, in the original it was at the start
The '1' is a perl-ism. Perl will return the value of the last true value in the boolean. To prevent people from taking shortcuts and expecting the sub to return false or the value of $red_button_pressed or $massive_failure we return one. Sooner or later it will no longer return what they think it does, and their code will melt (see also bitrot).

-jackdied

Replies are listed 'Best First'.
Re: Re: Re: Conditional style (if, &&) query
by blakem (Monsignor) on Oct 17, 2001 at 03:21 UTC
    Your last bit of code confused me....
    return 1 && $a && $b;
    is identical to
    return $a && $b;
    is identical to
    return 1 && 1 && 1 && $a && $b
    So I don't follow your last paragraph...

    Update
    Were you perhaps thinking of:

    return $a && $b && 1;
    which will "coerce" all TRUE responses to be 1 instead of the value of $b?

    -Blake