Why is object destructor not called when script terminates ?

Posted by planetp on Stack Overflow See other posts from Stack Overflow or by planetp
Published on 2010-04-13T11:19:15Z Indexed on 2010/04/13 11:23 UTC
Read the original article Hit count: 189

Filed under:
|
|

I have a test script like this:

package Test;
sub new { bless {} }
sub DESTROY { print "in DESTROY\n" }

package main;
my $t = new Test;
sleep 10;

The destructor is called after sleep returns (and before the program terminates). But it's not called if the script is terminated with Ctrl-C. Is it possible to have the destructor called in this case also?

© Stack Overflow or respective owner

Related posts about perl

Related posts about destroy