Hi,

Edward: Your script doesn't work, as you are only opening the file in
read mode.  Read/write doesn't do want you want either.

If you want a quick'n'easy one liner, then use -i:

-i[extension]   edit <> files in place (makes backup if extension supplied)

Your one liner would look like:

perl -ne 'print unless /perl/' -ibak FILENAME


Now, two other solutions...

1. Open the file in read-write mode
2. Push lines to keep in to a buffer.
3. Seek byte 0, truncate the file, and write buffer to file.

Or you extend this to overwrite the file as you go along, seeking
between the position you are overwriting and the position you are
looking at.

Both these alternative solutions could leave the file being processed
destroyed if the script is interrupted.  At least by using two files
the file move is "atomic", so you either have the original or the
changed version - not somewhere in between.

Jonathan Paton

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to