If that still doesn't work, perhaps because it relies on features of
your I/O implementation, you may need to use the following
seek code, which remembers the old file position
explicitly and returns there directly.
for (;;) {
for ($curpos = tell(LOGFILE); <LOGFILE>; $curpos = tell(LOGFILE)) {
# process $_ here
}
sleep $naptime;
seek(LOGFILE, $curpos, 0); # seek to where we had been
}
On some kinds of filesystems, the file could be removed while you are
reading it. If so, there's probably little reason to continue
checking whether it grows. To make the program exit in that case,
stat the handle and make sure its link count (the
third field in the return list) hasn't gone to 0:
exit if (stat(LOGFILE))[3] = = 0