How to set the code that should be executed before stopping the Perl script?
Here's how to run a piece of code just before exiting the Perl script. I read about the END routine, but it is only executed if the script ends normally. However, I want the code to be executed as well, if, for example, the user interrupts the program using ^ C.
Trapping completion signals and redirecting them so something is easiest:
$SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { die; };