根据solution provided in perldoc,我试图效仿tail -f
,但它不能按预期工作。下面的代码可以首次打印所有行,但不会附加新行。请您详细说明我是否在此遗漏任何事情。在Perl中模拟tail -f
#!/usr/bin/perl
open (LOGFILE, "aa") or die "could not open file reason $! \n";
for (;;)
{
seek(LOGFILE,0,1); ### clear OF condition
for ($curpos = tell(LOGFILE); <LOGFILE>; $curpos = tell(LOGFILE))
{
print "$_ \n";
}
sleep 1;
seek(LOGFILE,$curpos,0); ### Setting cursor at the EOF
}
“aa”是什么意思? – sarnold
aa是不断增长的文件名,我需要做tail -f aa。 – user419534
另请参阅[File :: Tail](http://search.cpan.org/perldoc?File::Tail) – ikegami