in reply to Temporary files and cleaning up after an interruption

How about something like this?

#!/usr/bin/env perl use strict; # ...it's not just for teachers anymore. my ($tmpFile, $finalFile); sub tidyUp { # Time to go! if ($tmpFile && (-e $tmpFile)) { unless (-e $finalFile) { rename($tmpFile, $finalFile) or die ">>> Can't move $tmpFile -> +$finalFile ($!)\n";; } else { die ">>> Can't move $tmpFile -> $finalFile because $finalFile al +ready exists!\n"; } } else { die ">>> No temporary file to move.\n"; } } # Now let's catch a few well known disruptive signals -- the troublema +kers ;] $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'ABRT'} = $SIG{'TERM'} = \&tidyUp; # Go on about your business ... open(tmpFile, $tmpFile);
...

Utterly untested and written in a browser window to boot. If this code kills your dog, you've got my sympathy. ;]

Cheers!

--j