in reply to Clobber instead of append
Example:
open(FILE, "+<$file"); my $temp; while(<FILE>) { $temp .= $_; } seek(FILE,0,0); print FILE $temp; truncate(FILE,tell(FILE)); close(FILE);
Of course, you'll want to add some dies to that.
If you're worried about memory usage, I'd suggest reading the file in one line at a time, writing out to a temp file one line at a time, then just moving the temp file over the original (don't forget to preserve permissions).
|
|---|