"be consistent" | |
PerlMonks |
Re: Or, Or, Equals Zero, $x ||= 0by markkawika (Monk) |
on Nov 28, 2007 at 00:33 UTC ( [id://653428]=note: print w/replies, xml ) | Need Help?? |
$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);
In Section
Seekers of Perl Wisdom
|
|