On 11/22/2011 04:27 PM, Mark Wagner wrote:
I want to update a status file, similar to this:

open OUTFILE, ">", "status.txt";
print OUTFILE "$last_date\n";
close OUTFILE;

However, if something goes wrong (e.g. the disk is full), this code
will replace "status.txt" with an empty file.  How can I update the
file while preserving the previous contents if something goes wrong?

use File::Slurp and its write_file sub. it has an atomic mode which makes sure you always have a clean file. it writes the file to a temp and then does a rename to the original file. the OS makes sure that is atomic.

uri

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to