退出拖尾文件 - 在 perl 中
我有这段代码,基本上是一个文件的尾部。 该文件每秒填充近 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,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.