Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Or, Or, Equals Zero, $x ||= 0

by markkawika (Monk)
on Nov 28, 2007 at 00:33 UTC ( [id://653428]=note: print w/replies, xml ) Need Help??


in reply to Or, Or, Equals Zero, $x ||= 0

$x ||= 0; translates to $x = $x || 0;. You might use this to assign a default value to a variable when you didn't want to test whether or not the variable is defined. $x stays the same if $x is defined and is not equal to zero. If it is equal to zero, it falls through the "or" (||) and sets it to zero.

So the only time this changes the value of $x is when $x is undefined. That's a short-hand way of writing:

$x = 0 if (!defined $x);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-23 20:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found