Hi,

I added one. The seek didn't work.
I don't have the ReadBackwards, but  at least some timeing results :

Benchmark: timing 10000 iterations of complete, frk, pop...
  complete: 21 wallclock secs (16.93 usr +  0.80 sys = 17.73 CPU) @ 564.02/s (n=10000)
       frk: 83 wallclock secs ( 1.34 usr  9.98 sys + 20.70 cusr 39.90 csys = 71.92 
CPU) @ 883.39/s (n=10000)
       pop: 18 wallclock secs (15.14 usr +  0.76 sys = 15.90 CPU) @ 628.93/s (n=10000)

# --------------------------------
#!/user/cadiclab/bin/perl

use strict;
use Benchmark;

my $file = "tst.cgi";

sub pop {
  open(FH, "< $file") or die "Problems opening file $! \n";
  my @lines = <FH>;
  my $lastline;
  while (my $line = pop @lines) {
      $lastline = $line;
      last;
  }
} # End sub pop

# --------

#sub readb {
  #use File::ReadBackwards;
  #my $bw = File::ReadBackwards->new( $file ) or die "Cannot read $file: $!";
  #my $last_line = $bw->readline;
#}

# --------

sub frk {
  my $last_line = `tail -1 $file`;
}

# --------

sub complete {
  open FILE, $file or die "Cannot read $file: $!";
  my $last_line;
  $last_line = $_ while <FILE>;
}


timethese (10000, {
        pop => \&pop,
        frk => \&frk,
        complete => \&complete });
        #readb => \&readb });

# -------------------------------

> 
> Karen Liew Ying Ping wrote:
> > 
> > Hi,
> 
> Hello,
> 
> > Let's say I'm opening a file.
> > How do I read the last line of the file?
> > is there any function in doing so?
> 
> 
> use File::ReadBackwards;
> my $bw = File::ReadBackwards->new( $file ) or die "Cannot read $file:
> $!";
> my $last_line = $bw->readline;
> 
> # OR
> 
> my $last_line = `tail -1 $file`;
> 
> # OR
> 
> open FILE, $file or die "Cannot read $file: $!";
> my $last_line;
> $last_line = $_ while <FILE>;
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to