in reply to A Better Way
Be aware that the way you've written the code is unsound in that it offers the potential for permanent (and possibly silent) data loss. Consider what happens if your:
fails. You're not checking print's return value, so you may not even be aware that it's failed. If it fails, your var.txt file will be corrupted. If you don't have a backup copy, you will have suffered permanent data loss.print XFIL $line;
Apart from the possibility of print failing (due to disk full or disk quota exceeded, for example), suppose your program gets interrupted during the print loop (via CTRL-C or other signal, OS restart, or a power failure, for instance). Because it was interrupted, your program had not finished writing the var.txt file. So when you now re-run your program, you will read (and write) an incomplete var.txt file. And again, you may not be immediately aware that you've (permanently) lost data.
I assume Tie::File will deal sensibly with these sort of routine robustness and reliability issues. If you don't use Tie::File, you can make your program more robust by:
Update: See also Perl Best Practices book: is this one a best practice or a dodgy practice?.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 22:53 UTC |