On Sun Jul 06 2008 @  8:09, loody wrote:
> Dear all:
> I try to read the last line of a file directly instead of using
> while(<>) or something else to read each line until "undef" bumped to
> me.
> If you know some build-in functions or another modules for me to use,
> please help me.

My first thought is File::ReadBackwards from the CPAN. Then it should be as
simple as this:
              
#!/usr/bin/perl
use strict;
use warnings;
use File::ReadBackwards;

my $bw = File::ReadBackwards->new( $ARGV[0] )
    or die "Can't read $ARGV[0]: $!";        

my $last_line = $bw->readline();

print "$last_line";

That takes the file to read from the command line, but you could obviously
specify what file (or files) you want to read in other ways.

Hope this helps, T

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to