我嘗試從后到頂部從陣列中讀取日志檔案,但是當日志關閉時,它會在以下之后完成并出現以下錯誤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);
}
uj5u.com熱心網友回復:
$bw 是一個物件,而不是檔案句柄。所以你需要使用方法呼叫關閉:
$bw->close();
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316268.html
