in reply to Re: Custom SIG DIE handler that isn't executed in evals
in thread Custom SIG DIE handler that isn't executed in evals

Hi, thats what local does for globals :) it saves the value until the end of the scope/block

{ local $SIG{__DIE__} = ...; } ## no sig handler here doEval(); sub doEval { local $SIG{__DIE__} = ...; ... } ## the end

Replies are listed 'Best First'.
Re^3: Custom SIG DIE handler that isn't executed in evals
by tunafish (Beadle) on Sep 14, 2016 at 04:14 UTC
    But what to do when the eval is deep within a bunch of system modules? I'm receiving e-mails right now from my script because of an eval located in /usr/local/lib64/perl5/XSLoader.pm

      But what to do when the eval is deep within a bunch of system modules?

      see perlvar#$^S

      Expanding on what the anony monk said, your die handler can test if the die happened in an eval.

      So, maybe the following:

      # not tested sub SigDieHandler { unless ($^S) # skip if die happened in an eval { ...; # create and send email } }

      Not tested, YMMV.