atexit.
Each package's
END block is called when the program or thread ends (see
the perlmod manpage manpage for more details).
Perl's exception-handling mechanism is its eval
operator. You
can use eval
as setjmp and die
as longjmp. For
details of this, see the section on signals, especially the time-out
handler for a blocking flock
in Signals and chapter 6 of the Camel.
If exception handling is all you're interested in, try the exceptions.pl library (part of the standard perl distribution).
If you want the atexit
syntax (and an rmexit
as well), try the AtExit module available from
CPAN.