On Wed, 2007-09-05 at 07:06 -0400, Chas Owens wrote: > On 9/4/07, sivasakthi <[EMAIL PROTECTED]> wrote: > snip > > Thanks for your suggestions.. but i need to read a file from backwards... > > First time reading from backwards & set the last line position to one > > variable..next time reading backwards until reach that variable position... > > is it possible to achieve that..???? > snip > > Yes, just save the value of tell before reading anything (this will be > the end of the file) and then stop reading when you reach that > position in the file. I have included a sample script that does that > very thing. It saves the position in a growing data section at the > end (to give it something to read on the next run). I am having a > hard time coming up with a reason why you would want to read a file > that grows in size backwards; if you don't mind my asking, why do you > need to do such an odd thing? >
Thanks for your response.. I have need to collect the possibilities of reading the log files and submitted to team for analyse.... the following code also achieved my requirement, #!/usr/bin/perl use strict; use warnings; use File::ReadBackwards ; my $bw = File::ReadBackwards->new( '/log/path' ) or die "can't read 'log_file' $!" ; my $first=1; open(FH,"position.txt"); $pos=<FH>; close FH; my $log_line; while( defined( $log_line = $bw->readline ) ) { my $cur_pos=$bw->tell; if($pos != $cur_pos) { if($first) { open(FH,">position.txt"); print FH $cur_pos; close FH; undef $first; } print "$log_line"; } else { exit; } } Thanks, Siva