Note that it's important to include the "die" call in the sub that gets assigned to $SIG{INT} -- otherwise, the script won't actually exit on ctrl-C.for(my $i=0;$i<50;$i++) { my $tmp = new File::Temp('DIR' => '/tmp', 'UNLINK' => 1); $SIG{INT} = sub { unlink "/tmp/".$tmp->filename; die }; ## <- add t +his line sleep(1); }
(Update -- to explain: when you interrupt the script, this will generally be during the sleep call, and unless you declare a signal handler to catch that, the File::Temp module will never get the chance to do its normal clean-up.)
Another update -- check the perlipc docs, and your own system's manual regarding signals; you'll probably want to trap other things in addition to SIGINT (e.g. SIGTERM, which is what the shell "kill" command sends by default).
In reply to Re: File::Temp.. What am I missing?
by graff
in thread File::Temp.. What am I missing?
by devnul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |