Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Conditional style (if, &&) query

by jackdied (Monk)
on Oct 17, 2001 at 03:12 UTC ( [id://119283]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://119283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found