in reply to Re^4: Localizing %SIG
in thread Localizing %SIG
Fair enough. Obviously, your reference to "It" wasn't specific enough. :-)
[Disclaimer: The following is my best guess. This isn't my area of expertise. I could be entirely wrong.]
In perlsub, under Localization of special variables, it says:
"If you localize a special variable, you'll be giving a new value to it, but its magic won't go away. That means that all side-effects related to this magic still work with the localized value."
Localizing %SIG and the $SIG{__WARN__} magic remains:
$ perl -wE 'warn 1; $SIG{__WARN__} = sub { say "WARN: $_[0]" }; warn 2 +; { local %SIG; warn 3 } warn 4' 1 at -e line 1. WARN: 2 at -e line 1. WARN: 3 at -e line 1. WARN: 4 at -e line 1.
However, localizing $SIG{__WARN__} and the magic is temporarily removed:
$ perl -wE 'warn 1; $SIG{__WARN__} = sub { say "WARN: $_[0]" }; warn 2 +; { local $SIG{__WARN__}; warn 3 } warn 4' 1 at -e line 1. WARN: 2 at -e line 1. 3 at -e line 1. WARN: 4 at -e line 1.
— Ken
|
---|