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

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-07-23 18:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.