in reply to perl die & exit values

See the documentation of die:

If an uncaught exception results in interpreter exit, the exit code is determined from the values of $! and $? with this pseudocode:
exit $! if $!; # errno exit $? >> 8 if $? >> 8; # child exit status exit 255; # last resort

And likely, $! is set from some other operation that your script (or Perl) performed. So you can't rely on a specific exit code if your script dies.

If you need something really specific, you could install your own handler via either an END block or a $SIG{__DIE__} handler (perlvar).

Replies are listed 'Best First'.
Re^2: perl die & exit values
by choroba (Cardinal) on Feb 26, 2018 at 15:36 UTC
    > you can't rely on a specific exit code if your script dies

    What about setting $! just before you die?

    $ perl; echo $? $!=42; die "Hello" __END__ Hello at - line 1. 42

    ($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,