> -----Original Message-----
> From: Jorge Goncalvez [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 07, 2001 6:10 AM
> To: [EMAIL PROTECTED]
> Subject: Re:Last line
> 
> 
> Hi, how to parse the last line of a file.
> 
> I have this code:
> $pb->destroy unless($last_line=~/^dhcpd|LOG_INFO|ftpd/);
> 
> $last_line=??
> 
> The file is already open.

No magic way to read the last line. You can read forward
through the file line-by-line, saving the last-read line. When you
get to eof, you'll have the last line saved. Simple, but not good 
if the file is huge.

Otherwise, you would typically seek to some offset before the
file length and read a block of data. Then scan backwards to find
the line separator to extract the last line.

CPAN has a File::Tail module which does all this and more. That's
what I would use.

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

Reply via email to