Re: Deleting last 12 lines of a large file

2003-01-27 Thread Janek Schleicher
On Sun, 26 Jan 2003 18:49:59 +0530, Sukrit wrote: > How do i delete the last 12 (or so) lines of a large file (400+ lines) > without loading the whole into memory. use Tie::File; tie @line, 'Tie::File', $filename or die "..."; splice @line, -12; untie @line; Greetings, Janek -- To unsubscrib

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Rob Dixon
Peter Scott wrote: > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (R. Joseph Newton) writes: >> Peter Scott wrote: >> >>> I$^I = ".bak"; >>> my @queue; >> >> Hmmm. >> >> push (@queue, $somevar); >> somevar = pop(@queue); >> >> ...and double-H! >> >> Could it be that that animal Perlites

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Rob Dixon
Peter Scott wrote: > In article <[EMAIL PROTECTED]>, > [EMAIL PROTECTED] (Rob Dixon) writes: >> What's the $^I variable? Is it a 5.8 addition? > > No, it's a 4.0 addition (or earlier). It's how to turn on the -i > command-line switch within code. See -i in the perlrun page. Ah, my font let me d

Re: Deleting last 12 lines of a large file

2003-01-26 Thread R. Joseph Newton
Sukrit wrote: > While waiting for your reply, my goals changed a bit. i got some sort > of worm (redlof if you must know) on my windows machine (with some > 11000 files affected). It tags to the end of every html file, so i > didn't want chomping of last 12 lines of files that hadn't got it :) > B

Re: Deleting last 12 lines of a large file

2003-01-26 Thread John Baker
On Mon, 27 Jan 2003, Sukrit wrote: > > While waiting for your reply, my goals changed a bit. i got some sort > of worm (redlof if you must know) on my windows machine (with some > 11000 files affected). It tags to the end of every html file, so i > didn't want chomping of last 12 lines of files tha

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Sukrit
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > "Rob" == Rob Dixon <[EMAIL PROTECTED]> writes: Rob> Sukrit wrote: >> Hi Listers, How do i delete the last 12 (or so) lines of a >> large file (400+ lines) without loading the whole into memory. Rob> 400 lines isn't too huge. I w

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Peter Scott
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Rob Dixon) writes: >Peter Scott wrote: >> 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

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Peter Scott
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (R. Joseph Newton) writes: >Peter Scott wrote: > >> I$^I = ".bak"; >> my @queue; > >Hmmm. > >push (@queue, $somevar); >somevar = pop(@queue); > >...and double-H! > >Could it be that that animal Perlites refer to as an array is really a linked l

Re: Deleting last 12 lines of a large file

2003-01-26 Thread R. Joseph Newton
Peter Scott wrote: > I$^I = ".bak"; > my @queue; Hmmm. push (@queue, $somevar); somevar = pop(@queue); ...and double-H! Could it be that that animal Perlites refer to as an array is really a linked list? Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mai

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Rob Dixon
Peter Scott wrote: > 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; > } Neat. I like that :) What's the $^I variable? Is i

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Peter Scott
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-re

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Rob Dixon
Rob Dixon wrote: > 400 lines isn't too huge. I would say just read the file once to count > the > lines. Then re-read it, printing twenty less lines than you counted. > It's > dirty but it's quick :) Sorry, I don't know where I got 20 from! That should be $lines -= 12, of course. Rob -- To u

Re: Deleting last 12 lines of a large file

2003-01-26 Thread Rob Dixon
Sukrit wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi Listers, > 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, print

Deleting last 12 lines of a large file

2003-01-26 Thread Sukrit
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Listers, How do i delete the last 12 (or so) lines of a large file (400+ lines) without loading the whole into memory. regards sukrit -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8