use strict;
use warnings;
my $growing_number;
# Handle Ctrl-C
$SIG{INT} = sub{
print "INT: last value of \$growing_number is: $growing_number\nTe
+rminating..\n";
exit;
};
# Handle Ctrl-Break
$SIG{BREAK} = sub{
print "BREAK: Currently \$growing_number is: $growing_number\n";
};
while (1){
$growing_number += time;
sleep 1;
}
__END__
BREAK: Currently $growing_number is: 10049615223
BREAK: Currently $growing_number is: 18424294603
BREAK: Currently $growing_number is: 23449102243
INT: last value of $growing_number is: 28473909892
Terminating..
L*
PS note also that if you put sleep 60 then the OS in question catch the signal every 60 seconds.. not so good. You can workaround it using sleep 1 for 1..60
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|