http://www.perlmonks.org?node_id=469108


in reply to removing lines from a file

...if regex... seek(LOG,0,0) || die "Seek error: $!"; ...process line... truncate(LOG,tell(LOG))

Unless I'm missing something, you've moved the filehandle position to the beginning with seek. When you subsequently truncate to size tell(LOG) it truncates it to zero size, because 0 is where you've seeked to.

Try setting the position to a variable first:

...if regex... $pos = tell(LOG) seek(LOG,0,0) || die "Seek error: $!"; ...process line... truncate(LOG,$pos)

That corrects the immediate problem, but will still leave the line in question in place. If you set a variable to the string length of the line you've matched, and

truncate(LOG,$pos-$stringlength);

that should get rid of your matched line.

Note: there may be better ways to do this.

Update: I also strongly agree with the first line of frodo72s response, especially as you've said that the file is growing quickly. I would be inclined to use two files, and write everything that doesn't match your regex out to the second file

--------------------------------------------------------------

g0n, backpropagated monk