I was testing that theory and it is in fact what is happening. The modified code below works and does not drop the first entry... also a bit easier to read. I would reccomend using while(1) for continous loops.
#!/usr/bin/perl -w
use strict;
my $LogFile="C:/test.txt";
my $naptime=3;
my $logpos;
#Reads LOGFILE continuously
open(LOGFILE,"<$LogFile") || die "Couldn't open file Status - $!\n";
while (1)
{
sleep $naptime;
$logpos = tell(LOGFILE);
while(<LOGFILE>)
{
print;
}
seek(LOGFILE, $logpos, 0); # seek to last known
}
<edit>the more I thought about it you don't even need the $logpos variable. Just use seek(LOGFILE,0,0) to seek to the beginning,since it seemed like what you wanted to do. Although if you have a specific point in the file you want to start reading from then you will need to predefine it and even then you still wouldn't need the call to tell(LOGFILE) I believe</edit> Hope this helps.
|