It's not a side-effect. It's not a bug. local undefines its argument.
The documentation Temporary Values via local() says:
.... The argument list may be assigned to if desired, which allows you to initialize your local variables. (If no initializer is given for a particular variable, it is created with an undefined value.)This does not say that the lvalues in the local argument list will be set undef and later the result of any initialiser will be assigned to it.
Taking the empirical approach:
gives:use strict ; use warnings ; our $fred = 78 ; { local $fred = $fred ? 'Was Defined' : '*undef*' ; print "\$fred = $fred\n" ; } ; print "\$fred = $fred\n" ;
$fred = Was Defined $fred = 78which reenforces the feeling that the variable being localised retains its old value up to the moment the new value is set.
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. The implementation may assume it doesn't matter -- we live and learn !
IMO, this quacks like a bug.
In reply to Re^4: Setting signal handlers considered unsafe?
by gone2015
in thread Setting signal handlers considered unsafe?
by gnosek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |