# Nice little code fragment to append to the end of a file. # Takes the name of the file to append to, followed by # all of the lines of text to append. sub SafeAppend { my ($file, @content) = @_; s/\n*$/\n/ foreach @content; local *FILE; open FILE, ">>$file" or die "ERROR: Cannot write $file: $!\n"; flock (FILE, LOCK_EX) or die "ERROR: Cannot lock $file: $!\n"; seek (FILE,0,2) or die "ERROR: Cannot seek to end of $file: $!\n"; print FILE foreach @content; close FILE or die "ERROR: Cannot close $file: $!\n"; }