good chemistry is complicated,
and a little bit messy -LW
Perl Best Practices book: is this one a best practice or a dodgy practice?by eyepopslikeamosquito (Chancellor)
|on Sep 03, 2005 at 00:38 UTC||Need Help??|
I'm very much enjoying reading Perl Best Practices. I find myself scribbling notes after almost every page; mainly concrete ideas for improving the quality and especially the maintainability of production Perl code at work. To me, this is the most important Perl book to be published for years, because it helps me sell Perl as a maintainable language to management.
However, the In-situ Arguments ("Allow the same filename to be specified for both input and output") practice described on page 304 in chapter 14 has me scratching my head, for it seems to me to be more a "dangerous practice" than a "best practice".
Here is a test program, derived from the example given in the book:
My problems with this code are:
As discussed in Re-runnably editing a file in place, it seems sounder to first write a temporary file. Once you're sure the temporary file has been written without error (and after the permissions on the temporary are updated to match the original) you then (atomically) rename the temporary file to the original. In that way, if writing the new file is interrupted for any reason, you can simply re-run the program without losing any data.
Please let me know what I've overlooked.