in reply to Change a line in a file
open appears to fail. Always check whether open succeeds: open T, "+<$trace" or die "$trace: $!";
When writing to a file, checking for errors from print and close can't harm either. You want to be informed if your disk has not enough space for the data.
You'd probably have to seek to the beginning of the file and truncate it before writing after reading. But if you want to be prepared for crashes between "truncate" and "print" and don't want to lose your data, you'd better write to a temporary file and then move it over the old file with rename.
Maybe Tie::File helps you solve your problem faster.
|
|---|