Will it make any difference in loading time or cpu resource usage to
use the `tail' command like 'qx/tail -n30 $file/' as apposed to something
in straight perl like this example that prints the last 30 lines of $log:
#!/usr/local/bin/perl
use strict;
use warnings;
my $log = shift;
print rb($log);
sub rb {
use File::ReadBackwards;
my $log = shift;
my (@ar,$logline);
my $bw = File::ReadBackwards->new( "$log" ) or
die "can't read <$log>: $!" ;
my $cnt = 0;
while( defined( $logline = $bw->readline ) ) {
$cnt++ if($logline);
if($cnt <= 30) {
push @ar,$logline;
}else{
last;
}
}
## reverse @ar
return reverse @ar;
}
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/