我尝试从数组中从后到上读取日志文件,但是当日志关闭时,它会在 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
出现问题的脚本部分:
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);
}
最佳答案
$bw 是一个对象,而不是文件句柄。所以你需要使用方法调用来关闭:
$bw->close();
关于perl - 从后到上读取日志文件 - perl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69432649/