good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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
you will see
since the subsequent aliasing of an undefined value in the already localized hash %SIG doesn't create the key __DIE__ in %SIG.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In reply to Re: Localizing %SIG
by shmem
|
|