in reply to Re: Re^2: To || or not to or and why.
in thread To || or not to or and why.
andmy $value = shift() || 'default';
will not work the same.my $value = shift() or 'default';
will set $value to the value returned by shift() if it is true and to 'default' if it is false.my $value = shift() || 'default';
will set $value to the value returned by shift() no matter what!my $value = shift() or 'default';
then run#temp.pl $value = $x or $y or $z; $value = $x || $y || $z; $value = $x or $y || $z; $value = $x || $y or $z;
it outputsperl -MO=Deparse,-p temp.pl
if you notice((($value = $x) or $y) or $z); ($value = (($x || $y) || $z)); (($value = $x) or ($y or $z)); (($value = ($x || $y)) or $z); temp.pl syntax OK
and$value = $x or $y or $z;
just set $value to the value of $x no matter what the value of $y or $z because or has a lower precidence than =.$value = $x or $y || $z;
will just set $value to the value of $x || $y no matter what the value of $z?$value = $x || $y or $z;
--
flounder
|
|---|