Re: how to get the last line of a file

2002-10-11 Thread david
Alex Chen wrote: > hi, all > > i want to know how to get the last line of > a file .i know the func read has a paramenter offset but i don't know how > to use it.please help!!! > > thanks > alex chen try this: #!/usr/bin/perl -w; use strict; my $line=''; my $byte=''; o

Re: how to get the last line of a file

2002-10-11 Thread John W. Krahn
Alex Chen wrote: > > hi, all Hello, > i want to know how to get the last line of > a file .i know the func read has a paramenter offset but i don't know how to > use it.please help!!! 1) Install http://search.cpan.org/author/URI/File-ReadBackwards-0.98/ use File::ReadBackwards; my $bw = Fil

RE: how to get the last line of a file

2002-10-11 Thread NYIMI Jose (BMB)
use Tie::File; tie @array, 'Tie::File', "file.txt" or die $!; my $last_line=$array[$#array]; José. > -Original Message- > From: alex chen [mailto:[EMAIL PROTECTED]] > Sent: Friday, October 11, 2002 8:57 AM > To: [EMAIL PROTECTED] > Subject: how to get the last line of a file > > > hi

Re: how to get the last line of a file

2002-10-11 Thread David Garamond
alex chen wrote: > hi, all > > i want to know how to get the last line of > a file .i know the func read has a paramenter offset but i don't know how to > use it.please help!!! the easy way (but inefficient): # read until the last line open F, "file.txt" or die $!; $last=$_ while ; the m

Re: how to get the last line of a file

2002-10-11 Thread Jean Padilla
Hi, Alex i suggest the following: #!/usr/local/bin/perl -w my $filename = "Your_file_name"; # if you are so lucky to work on Unix my $lastline = `tail -1 $filename`; print $lastline; # if file is small enough to hold in an array open(FILE, $filename) or die "Can't open $filename.\n"; my @array