in reply to Using read/write to update a file

Although there are some ways around, you usually can't update an existing file, except sometimes when it has fixed length records (e.g. database context). The solution is usually to write to another file and then replace the old file by the new one, doing the renaming etc. Or, if your file is not too large, to first read from the file into memory (for example into an array of lines), to make the changes in memory, and to write the memory content onto the file at the end (that's essentially what happens when you open a file with a text editor, with MS Word or similar applications).

Using the -i command line flag or the Tie::File module can enable you to get away with this, but this is only because the dirty house-keeping aspects are basically hidden behind a smokescreen.

Replies are listed 'Best First'.
Re^2: Using read/write to update a file
by karlgoethebier (Abbot) on Oct 15, 2014 at 15:39 UTC
    "Although there are some ways around, you usually can't update an existing file ... except sometimes ... only because the dirty house-keeping aspects are basically hidden behind a smokescreen."

    Chief Vitalstatistix, the famous leader of the Gaulish village had the only fear that the sky may fall on his head tomorrow.

    But fortunately this didn't happen until today ;-)

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»