in reply to Localizing %SIG
I expected this to just turn off all handlers. Why do i need to write local $SIG{__DIE__};? Can anybody explain this?
Localizing a hash just creates an empty alias, with no key whatsoever. With local $SIG{__DIE__} you explicitly set the __DIE__ handler to undef, so for this context, you get back the default behavior of die, and die is done, signal processed. If you just localize %SIG, the __DIE__ handler of the surrounding context is still in place, since the __DIE__ signal isn't handled by the current localized %SIG (there is no __DIE__ key in %SIG) - so it is passed up and hits the handler installed before the localization. Does that make sense to you?
Update: the question from the previous paragraph just indicates that the explanation is poor, i.e. uncomplete. Further then:
Localizing a hash just creates an empty alias, with no key whatsoever. The processing of a signal via a custom handler is dependent on the presence of the signal name as key in the hash %SIG.
If you say local $SIG{__DIE__}, you just alias the value of the slot __DIE__ of the %SIG currently in place. If you localize the entire %SIG without further ado, this has no effect whatsoever, since it has no keys. Aliasing doesn't create keys! So, if you write something like
$SIG{__DIE__}= sub {print "fubar!\n"}; eval { local %SIG; local $SIG{__DIE__}; $a/$b }; print $@;
you will see
fubar! Illegal division by zero at - line 5.
since the subsequent aliasing of an undefined value in the already localized hash %SIG doesn't create the key __DIE__ in %SIG.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Localizing %SIG
by Anonymous Monk on Feb 17, 2016 at 13:25 UTC | |
by kcott (Archbishop) on Feb 17, 2016 at 21:23 UTC | |
by Anonymous Monk on Feb 17, 2016 at 22:13 UTC | |
by shmem (Chancellor) on Feb 17, 2016 at 22:57 UTC | |
by Anonymous Monk on Feb 18, 2016 at 08:25 UTC | |
by kcott (Archbishop) on Feb 17, 2016 at 23:34 UTC | |
by LanX (Saint) on Feb 17, 2016 at 22:50 UTC | |
by shmem (Chancellor) on Feb 17, 2016 at 23:27 UTC | |
|