James Sabre wrote:Since your are reading the whole file into memory you can safely re-open the file and write to it i.e.
I would NEVER write the changed lines out to the same file. Odds are too great that you screw something up, and your original file is lost forever. I'd always write the output to a new temp file, inspect it to be sure it is correct, and then rename the original as a .old or some such.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors