I try to read log files from array from back to top but when log is closed it finish with follow error after close($bw);
:
Not a GLOB reference at script.pl line 171.
at /script.pl line 171.
main::process_log("file.log") called at script.pl line 179
Part of the script where issue appear:
for my $file (@logs){
process_log $file;
}
sub process_log {
my $bw;
$bw = File::ReadBackwards->new( $file ) or die "can't read $file $!" ;
my $filename = 'status.log';
open(FW, '>', $filename) or die $!;
print FW "Processing file: $file\n";
close(FW);
$file =~ m"$logdir/(\w )/(\w )/(\w \-*\w*\-*\w*)/(.*\.log)$";
my $cmppattern = "${date}T${hour}";
my $row;
while( defined( $row = $bw->readline ) ) {
if ( $row =~ m/^$cmppattern/ ) {
#DO SOMETHING
last if ( $nlines > 0 && $row !~ m/^$cmppattern/ )
}
close($bw);
}
CodePudding user response:
$bw is an object, not a file handle. So you need to close using a method call:
$bw->close();