退出跟踪文件-在perl中



这段代码基本上结束了一个文件。

这个文件以每秒近100个条目的速度填充。
open (MYFILE, 'output.txt');
for (;;)
{
    while (<MYFILE>)
    {
        chomp;
        my $test=$_;
        if  ($test =~ m/^ok/)
        {
            $passed++;
            print "Number of passed :$passedn";
            print "Number of failed :$failedn";
        }
        elsif ($test =~ m/^not/)
        {
            $failed++;
            print "Number of passed :$passedn";
            print "Number of failed :$failedn";
        }
        elsif ($test =~ m/^The time taken is: (.*)/)
        { push (@array, "$1") ; }
        $row++;
    }
sleep (5);
print "It has been ".(time - $time)."secondsn";
seek(MYFILE, 0, 1);
}

所有这些都工作得很好,但是我希望这个perl脚本在文件output.txt不再被填充时自动退出。

除了使用标志技术之外,还有其他方法吗?perl?

据我所知,Perl没有内置任何东西。您可以检查文件大小(使用tell),记录文件大小更改的时间,如果距离上次更改时间过长,则退出。

最新更新