in reply to Inserting a line in the middle of a text

Well, the first question is "How would you do this in any arbitrary computer language?" The second is "How do you expect to insert a record into a file without writing into it?"

There are numerous ways of doing this in Perl: localize $/, and slurp the file in as one chunk, and read the file into an array, and read the file a line at a time, and either write the modified file as a temp file and use rename to overwrite the old file or use the -i option to edit it in place. You could also use Tie::File, although that seems to some of the aesthetics of using a sledgehammer to kill a gnat.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

  • Comment on Re: Inserting a line in the middle of a text