Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm outputting text to a file, and I save the position where I'm at (using tell), and then continue outputting more text. Eventually, I need to go back to the middle of the output file (using seek) and insert more text without overwriting any of the pre-existing text. Of course, the first time I tried, the text was overwritten, line-by-line.
I tried fiddling with the open(FILE,">output") line, using ">>output" and various combinations of "+>output" etc. The >> caused stuff to be appended to the very end of the output file, like normal, even if I had moved the location pointer with seek, which makes sense.
I really don't want to have to read the entire file, line-by-line, to a temp file, insert my new text at the break point, and then finish inserting the reset of the file. I'm thinking stuff can blow up if there's a crash in the middle, with half the information transferred, leaving me with half a good file with the right filename and the other half in a dummy filename
Thanks for any insight into this manner. And please forgive me if I've overlooked a simple solution - it's happened before, but this time I'm pretty sure I've thought the problem through. And also excuse my rambling verbosity; it's been a looong day.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inserting text into the middle of a file without clobbering any other text
by theorbtwo (Prior) on Jul 31, 2002 at 22:07 UTC | |
|
Re: Inserting text into the middle of a file without clobbering any other text
by tachyon (Chancellor) on Jul 31, 2002 at 23:56 UTC | |
by Anonymous Monk on Aug 01, 2002 at 15:53 UTC | |
by graff (Chancellor) on Aug 02, 2002 at 04:16 UTC |