Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Variable assignment error checking

by Anonymous Monk
on Dec 15, 2013 at 09:06 UTC ( [id://1067215]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Variable assignment error checking
in thread Variable assignment error checking

Call the function cough($cough) only if $cough is true?

Replies are listed 'Best First'.
Re^5: Variable assignment error checking
by Anonymous Monk on Dec 15, 2013 at 10:13 UTC

      It is not! In this expression:

      $var = func($var) || $var;

      the return value of func($var) will be assigned to $var if func($var) is true, otherwise the value of $var. In this expression

      $var ||= func( $var );

      the return value of func($var) will be assigned to $var if $var is false.

      Completely different logic!

      The expression $var ||= func( $var ); is shorthand for $var = $var || func( $var );. Can you spot the difference?

        $var = $var || func( $var ); $var = func( $var ) || $var;
        They're certainly logically equivalent if we disregard the short-circuiting nature of operators. (Though the mathematics branch of logic generally deals with no other return values than true and false...)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found