"be consistent" | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
... the second suggested solution--using the IO::Insitu module--does use a back-up strategy to ensure that data is not lost if the program abends. True. But it is still not re-runnable. Which makes it dangerous in the hands of naive users who interrupt a program with CTRL-C, then re-run it. If they do that, they may suffer permanent data loss and without being aware of it. It seems to me that you can get re-runnability with little extra effort: simply write the temporary file first and only overwrite the original (via atomic rename) after the temporary has been successfully written. As a test, I pressed CTRL-C midway through running this test program: This is what I saw: Now, of course, blindly re-running the test program resulted in permanent data loss (an empty fred.tmp file in this example). Update: Just to clarify, this problem is broader than the naive user scenario given above and may bite you anytime a script is automatically rerun after an interruption -- a script that is run automatically at boot time, for example. Further update: More detail on Win32 rename, related to tye's response below, can now be found at Re^7: Read in hostfile, modify, output. In reply to Re^2: Perl Best Practices book: is this one a best practice or a dodgy practice?
by eyepopslikeamosquito
|
|