I'm pretty new at this, and I'm trying to figure out how Perl's classes work with signals.
Specifically, it doesn't seem that a class's DESTROY function is called when you Ctrl-C the program.

I tried using use sigtrap qw(handler DESTROY INT QUIT); , but I'm not even sure this is the proper way to catch the signal. Either way, it seems I no longer receive a reference to my object when DESTROY is called. I keep getting this error:

Can't locate object method "time_passed" via package "INT" (perhaps you forgot to load "INT"?) at /var/local/bush/lib/ASH/Basic.pm line 113.

Here is my DESTROY function:

sub DESTROY {
	my $self = shift;
	
	my $runtime = time_passed(); 
	print "Total run time: $runtime\n";
	
	close(ERR);
	close(WARN);
	
	-d $self->{DIR}{THRESHOLD} ? print "All files saved to $self->{DIR}{THRESHOLD}.\n" : print "Self destroyed.\n";
	die("done.\n\n");
}

Thanks for the help!

The error message indicates you haven't loaded a module, or the syntax you are using is incorrect for the 'time_passed' function. Have you installed the module 'Basic.pm' correctly?

Read about Perl's %SIG hash - it is used for several signal functions.

$SIG{INT} = 'IGNORE';

will ignore Ctrl-C

Going back through my old posts, I realized I figured out a solution to this problem -- I'll find the code and post it here asap.

because the the first argument is the signal which is INT, so with INT you will not get anything. default argument will be the signal caught.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.