in reply to Re^2: Elegant Way of Inserting Text at the Start of the File
in thread Elegant Way of Inserting Text at the Start of the File

So, this will print the Hello as the first line, but it means that I have to open the file, output the result to a new file, delete the old file, and rename the new file as the old file.

Yes, you will have to do some variation of that. Like I said earlier, it's impossible to insert into a file.

The most straightforward alternative is to load the file into memory, seek to the start of the file, then output the modified file. I guess that's where ig's code is useful.

  • Comment on Re^3: Elegant Way of Inserting Text at the Start of the File