Boldra has asked for the wisdom of the Perl Monks concerning the following question:

In perl5.10 the behaviour of a die handler is inconsistent:

$SIG{__DIE__} = sub { print "\$@='$@'\n"; $@='' }; eval {die "string" }; print "\$@='$@'\n"; eval {die { } }; print "\$@='$@'\n";

If the die gets passed a string, the signal handler has a local $@ which is empty, and modifying it doesn't affect the caller. If it gets passed a hashref, it doesn't localize it, and modifying it (calling eval inside sigdie) changes it in the caller's scope.

I know it was fixed by 5.18. I've tried finding it in perldelta, but I think I'm searching for the wrong thing. Does anyone know which Perl version this was fixed in? Thanks.

edit: missing semicolon



- Boldra

Replies are listed 'Best First'.
Re: When was $@ scope in sigdie fixed?
by Apero (Scribe) on Dec 07, 2015 at 11:56 UTC

    Version 5.14 is the exact value you're looking for, per the changelog notes at Exception Handling. This version can be enforced in code where this is a mandatory requirement with the stanza:

    require v5.014_000;
    .. which will cause code to die when that stanza is hit (or substitute use for require to make that a compile-time check, although IIRC that also enables some optional features as of that version by default as well.)

        You're right that the first of your suggested forms is the recommended method for maximum comparability.

        Incidentally, any of those 3 forms work counting mine, at least in reasonably-recent Perl versions (though I'm not exactly sure how old would break with that.) I had intended for the form that dropped the leading v as the documentation says it's more backwards-compatible, but there it is.

Re: When was $@ scope in sigdie fixed?
by choroba (Cardinal) on Dec 07, 2015 at 11:59 UTC
    I'm not sure, but maybe perl5140delta, see Exception Handling.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: When was $@ scope in sigdie fixed?
by Anonymous Monk on Dec 07, 2015 at 12:02 UTC