in reply to In place editing of text files
Reading from a file and in the same moment writing to it is rarely what you want to do. Consider a file to be much like a vinyl record - the read-write head moves forward. If you read a line, the read-write head is now at the end of that line. You then write your modified line to it. This likely is not what you want.
I recommend either slurping the whole file into memory before modifying, then writing it out as a whole again. Alternatively you can use Tie::File, which allows you to treat a file as an array. The most sane solution would be to use a templating module, like Template Toolkit for example.
|
|---|