Yo, Mark,
On Mon, 9 Dec 2002, Mark Goland wrote:
> Ok I got it working now, thanx much Jason. Only question I have is
> regarding this.
Good! Glad I could help.
> $head ||= $link;
This is a Perl idiom to set a variable if it hasn't already been set.
So, if $head == undef, then $head will be set to $link.
The $lvalue X= $rvalue operators all do this:
$lvalue = $lvalue X $rvalue;
And due to precedence ('=' is very low precedence), this is really:
$lvalue = ( $lvalue X $rvalue );
Since Perl's '||' operator does not return a boolean but the actual
value that caused the test to succeed, this:
( $lvalue X $rvalue ) will return $lvalue or $rvalue (or 0 if neither
evaluate to true). Using this feature, I hope you see that
$lvalue ||= $rvalue
is equivalent to
$lvalue = $rvalue unless $lvalue;
(TMTOWTDI...) Enjoy! HTH, :)
---Jason
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]