develooper Front page | perl.beginners | Postings from January 2007

Re: Read a text file starting from the bottom

Thread Previous | Thread Next
From:
Rob Dixon
Date:
January 15, 2007 04:02
Subject:
Re: Read a text file starting from the bottom
Message ID:
45AB6BA9.7020508@350.com
Michael Alipio wrote:
> 
> I wanted to extract the start time of a particular logfile (located at the
> beginning of the file, and also the end time which is located at the end of
> the logfile.
> 
> Is there any way to do this in perl without using "head" or "tail" commands?

To read a file backwards, you could make use of File::ReadBackwards. The code
below assumes that you log file is called 'logfile'.

use strict;
use warnings;

use File::ReadBackwards;

my $fh = File::ReadBackwards->new('logfile');

my $last_line = $fh->readline;


 > By the way, can you point me somewhere perhaps a perl function that lets you
 > create directories?

To create a directory use the mkdir() built-in function. It may be more
convenient to use the File::Path module, which provides a mkpath() function
which will also create any intermediate necessary to form a complete path. (It
also offers an rmtree() function.)

HTH,

Rob


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About