in reply to Re: Re: replacing in file
in thread replacing in file

Here's (roughly) what Perl does when you use the -pi.bak flag on the file filename (and what you'll have to emulate):
  1. Open the file "filename" for read, with handle READ
  2. Rename "filename" to "filename.bak"
  3. Open the file "filename" for write+truncate with handle WRITE
  4. Read through all the lines from READ, modify them, then print them to WRITE