--------------------------------------------------------- $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
In reply to Re: Perl Idioms Explained - && and || "Short Circuit" operators
by Abigail-II
in thread Perl Idioms Explained - && and || "Short Circuit" operators
by davido
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |