退出拖尾文件 - 在 perl 中

发布于 2024-12-10 15:18:44 字数 836 浏览 0 评论 0原文

我有这段代码,基本上是一个文件的尾部。 该文件每秒填充近 100 个条目。

open (MYFILE, 'output.txt');
for (;;)
{
    while (<MYFILE>)
    {
        chomp;
        my $test=$_;
        if  ($test =~ m/^ok/)
        {
            $passed++;
            print "Number of passed :$passed\n";
            print "Number of failed :$failed\n";
        }
        elsif ($test =~ m/^not/)
        {
            $failed++;
            print "Number of passed :$passed\n";
            print "Number of failed :$failed\n";
        }
        elsif ($test =~ m/^The time taken is: (.*)/)
        { push (@array, "$1") ; }
        $row++;

    }
sleep (5);
print "It has been ".(time - $time)."seconds\n";
seek(MYFILE, 0, 1);

}

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

除了使用旗帜技术? perl 做出的规定?

I have this bit of code which basically tails a file.
This file is populated with nearly 100 entries every second.

open (MYFILE, 'output.txt');
for (;;)
{
    while (<MYFILE>)
    {
        chomp;
        my $test=$_;
        if  ($test =~ m/^ok/)
        {
            $passed++;
            print "Number of passed :$passed\n";
            print "Number of failed :$failed\n";
        }
        elsif ($test =~ m/^not/)
        {
            $failed++;
            print "Number of passed :$passed\n";
            print "Number of failed :$failed\n";
        }
        elsif ($test =~ m/^The time taken is: (.*)/)
        { push (@array, "$1") ; }
        $row++;

    }
sleep (5);
print "It has been ".(time - $time)."seconds\n";
seek(MYFILE, 0, 1);

}

All of this works fine, but I want this perl script to exit automatically when the file output.txt is not getting populated any further.

Is there a way apart from using a flag technique? A provision made by perl?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手心的温暖 2024-12-17 15:18:44

据我所知,Perl 中没有内置任何内容。您可以检查文件大小(使用 tell),记录文件大小更改的时间,如果自上次更改以来已经过去了太多时间,则退出。

There's nothing built into Perl that I know of. You could check the file size (using tell), record the time when the file size changes, and exit if too much time has passed since the last change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文