There is another one from perl monks, that may be easier:
this one is good for fixed length records in a data file or you can adapt
this
to search for \n as well, like the other
# gets last 100 bytes of the file
if (open (FH, "file"))
{
  seek FH, -100, 2;
  while (<FH>)
  {
    print $_;
  }
  close (FH);
}

> -----Original Message-----
> From: Nikola Janceski [mailto:nikola_janceski@;summithq.com]
> Sent: Monday, October 28, 2002 2:42 PM
> To: 'Kipp, James'
> Subject: RE: Trailing 5 lines of a file
> 
> 
> thanx... I think I can fix it to get any number of lines that 
> I ask for.
> 
> > -----Original Message-----
> > From: Kipp, James [mailto:James.Kipp@;mbna.com]
> > Sent: Monday, October 28, 2002 2:09 PM
> > To: 'Nikola Janceski'; Beginners (E-mail)
> > Subject: RE: Trailing 5 lines of a file
> > 
> > 
> > > 
> > > without using 'tail' how can I get the trailing 5 lines of a 
> > > large file
> > > quickly, without loading it all to memory?
> > > 
> > > is there anyway without pop and shifting through an array 
> > > foreach line? (<=
> > > 
> > 
> > somebody posted this code last week, which gets the last line 
> > of the file
> > --
> > open F, "file.txt" or die $!;
> > seek F, 0, 2;
> > while ($pos = tell F) {
> >     seek F, -($pos > 1024 ? 1024 : $pos), 1 or die;
> >     read F, $block, 1024;
> >     $_ .= $block;
> >     do {$last = $1; print "$last"; last} if /.+\n(.+)/s;
> > }
> > 
> > ---
> > the part I am not sure about is the do block ( i never use 
> > them). This works
> > for getting last line, so it should not be too hard to change 
> > it to  get the
> > last 5 
> > 
> 
> --------------------------------------------------------------
> --------------
> --------------------
> The views and opinions expressed in this email message are 
> the sender's
> own, and do not necessarily represent the views and opinions of Summit
> Systems Inc.
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to