In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Rob Dixon) writes: >Sukrit wrote: >> How do i delete the last 12 (or so) lines of a large file (400+ lines) >> without loading the whole into memory. > >400 lines isn't too huge. I would say just read the file once to count >the >lines. Then re-read it, printing [12] less lines than you counted.
Maybe each line is a megabyte long? :-) Anyway, here's a way that doesn't require keeping more than 12 lines in memory and doesn't require reading twice: $^I = ".bak"; my @queue; while (<>) { push @queue, $_; print shift @queue if @queue > 12; } -- Peter Scott http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]