Greetings...

Peter's solution is the one I would recommend unless you are reading large
files and/or your system has little memory available.  By reading into an
array, the entire file will be pulled into memory.  If memory use is an
issue, you could use something like this:

-----

open(FILE, "my_file.txt") or die;

$pos = -2;  # Use this to get past EOF and last newline

while($char ne "\n")
{
     seek FILE, $pos, 2;
     read FILE, $char, 1;
     $pos--;
}

$final = <FILE>;
print "Last line is: $final\n";

-----


Jeremy Elston
Sr. Staff Unix System Administrator
Electronic Brokerage Technology
Charles Schwab & Co., Inc.

"Life is the final exam where no one can cheat, because we all have
different problems to solve."

WARNING:  All email sent to this address will be received by the Charles
Schwab Corporate email system and is subject to archival and review by
someone other than the recipient


-----Original Message-----
From: Ricardo Cumberbatch L. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 15, 2001 7:24 AM
To: Perl-Unix-Users
Subject: [Perl-unix-users] Read the Last line in a file


Hi every one I had to do a perl script but a need to know how in perl you
do to read the last line in a file, I no to read in a file but how to read
every time a need the last line in a file.

Thanks for the help folk...


R.C.L. ( ^_^ )


_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users
_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users

Reply via email to