in reply to HELP!! urgent!writing contents toa specific line in an existing file

There's an entry in perlfaq5, How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?. The current answer is quite boring:
Use the Tie::File module, which is included in the standard distribution since Perl 5.8.0.

I like the old answer (perl 5.6.x) much better — and much more fitting for solving a homework problem:

Those are operations of a text editor. Perl is not a text editor. Perl is a programming language. You have to decompose the problem into low-level calls to read, write, open, close, and seek.

Although humans have an easy time thinking of a text file as being a sequence of lines that operates much like a stack of playing cards -- or punch cards -- computers usually see the text file as a sequence of bytes. In general, there's no direct way for Perl to seek to a particular line of a file, insert text into a file, or remove text from a file.

(etc...)

  • Comment on Re: HELP!! urgent!writing contents toa specific line in an existing file

Replies are listed 'Best First'.
Re^2: HELP!! urgent!writing contents toa specific line in an existing file
by Somni (Friar) on Nov 15, 2007 at 13:18 UTC
    I liked that old answer so much I copied it here. It's a shame they gutted the entry.