Perl destructor not being called? Here's why

If you’re using a Perl destructor method (‘DESTROY’, ‘DEMOLISH’) it may not be called if the Perl process is terminated abruptly by a signal. To fix this, just add the sigtrap pragma to your program:

use sigtrap qw/die normal-signals/;

Now if the program receives a SIGINT or SIGTERM, the Perl process will die and call the destructor.

To read more on signal handlers see our article: Catch and Handle Signals in Perl


David Farrell

David is the founder and editor of An organizer of the New York Perl Meetup, he works for ZipRecruiter as a software developer.

Browse their articles