Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl Idioms Explained - && and || "Short Circuit" operators

by Abigail-II (Bishop)
on Oct 22, 2003 at 21:31 UTC ( #301380=note: print w/ replies, xml ) Need Help??


in reply to Perl Idioms Explained - && and || "Short Circuit" operators

--------------------------------------------------------- $this && $that | If $this is true, and $that is true | return the value of the last | expression evaluated ($that). -----------------+--------------------------------------- $this || $that | If $this evaluates true, stop | evaluating, we're done. Otherwise | evaluate $that for truthfulness. | If $that evaluates true, return | the value of $that. ---------------------------------------------------------

That doesn't explain what is returned if $that is false. May I suggest the following (which is shorter, symmetric, and explains the return value on failure).

--------------------------------------------------------- $this && $that | If $this is true, return $that, | else return $this. -----------------+--------------------------------------- $this || $that | If $this is true, return $this, | else return $that. ---------------------------------------------------------

Abigail


Comment on Re: Perl Idioms Explained - && and || "Short Circuit" operators
Select or Download Code
Re: Re: Perl Idioms Explained - && and || "Short Circuit" operators
by davido (Archbishop) on Oct 22, 2003 at 21:34 UTC
    Thanks Abigail. The node has been updated per your suggestion. Good catch.

    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-08-30 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls