The documentation Temporary Values via local() says
I agree. The docs are misleading. local actually does the same thing whether an assignment ("initializer") is present or not. local doesn't even know of the presence of an assignment. Similarly The assignment doesn't know local is present.
Were it not for the side effect of setting $SIG{ALRM} to undef, nobody would ever be able to tell that being set undef is apparently a step in the initialisation of the local.
Not so. I rely on that feature all the time.
sub d :lvalue {
print("$_[0]: ", defined($_[1]) ? "[$_[1]]" : "undef", "\n");
$_[1]
}
our $fred = 78;
d("pre local", $fred);
d("post local", local $fred);
gives
pre local: [78]
post local: undef
It can also be seen with an "initializer" present.
sub d :lvalue {
print("$_[0]: ", defined($_[1]) ? "[$_[1]]" : "undef", "\n");
$_[1]
}
our $fred = 78;
d("pre local", $fred);
d("post assign", d("post local", local $fred) = 90);
pre local: [78]
post local: undef
post assign: [90]
|