It depends on how the script is being killed. A kill -9 on unix can not be trapped, nor can someone pulling the plug out the wall. That aside you can set a signal handler, here is an example that traps the Ctrl-C by setting the $SIG{INT} handler to a subroutine reference. It also has an END block just for fun (any cleanup you do in normal termination could be here and it will get run after the sig handler)
$ perl -le'$SIG{INT}=sub{print "cleanup"};sleep 100;END{print "goodbye +"}' # here I hit Ctrl-C cleanup goodbye $
Cheers,
R.
In reply to Re: Perl action on cancellation
by Random_Walk
in thread Perl action on cancellation
by Win
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |