<Tim Kazner> wrote in comp.lang.perl.misc:
Randal L. Schwartz schreef:
defined $_ or $_ = 1 for $base_ref->{pl};
[...]
use strict;
use warnings;
my ($base_ref,$v) = ({});
$$v=1 if ($v=\$base_ref->{pl} and !defined $$v);
print "$$v\n";
($base_ref,$v) = ({pl=>8});
$$v=1 if ($v=\$base_ref->{pl} and !defined $$v);
print "$$v\n";
__END__
1
8
What is the advantage over
defined or $_ = 1 for $base_ref->{pl};
Especially considering that $v is undeclared. That would also have
to be done somewhere.
Yes it might be something to benchmark.
Implicit alias for lvalue works too. $_ and $v are both asignments.
Not really sure but 'for' may have more overhead than 'if'
and aliasing may be internal shorthand so that $_ ~ $$v;
Either way, both these
defined or $_ = 1 for $base_ref->{pl};
$$v=1 unless defined ${ $v=\$base_ref->{pl} };
would seem to incurr an overhead asignment that
if (!defined $base_ref->{pl}) {
$base_ref->{pl} = 1;
}
doesen't, if $base_ref->{pl} is defined.