#!/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 already exists!\n"; } } else { die ">>> No temporary file to move.\n"; } } # Now let's catch a few well known disruptive signals -- the troublemakers ;] $SIG{'INT'} = $SIG{'QUIT'} = $SIG{'ABRT'} = $SIG{'TERM'} = \&tidyUp; # Go on about your business ... open(tmpFile, $tmpFile);