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

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

by markkawika (Monk)
on Nov 28, 2007 at 00:33 UTC ( #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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2023-01-29 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?