Hi, I have a text file which has some lines, I may append others periodically, so I want a code that trails it (say at an interval of 5 seconds). When it sees that for 5 consecutive intervals no new line has been appended, the code decides to exit. Here's what I have come up with:
[code]
open f, "trail.txt";
while (1) {
while (<f>) {$count++; print; }
$rem++ if $count == 0;
$rem = 0 if $count > 0;
if ($rem < 5) {
sleep 10;
seek(f, 0, 2);
$count = 0;
}
else { last; }
}
[/code]
Line 3 maintains the number of lines newly appended. If 0, then current value of [b]$rem[/b] is increased by 1 signifying that 4 more of that, and the code should exit, while line 5 flushes [b]$rem[/b] if some line is appended. After printing out the newly appended lines, the code waits for 10 seconds, and repeats its action. The problem is that if the text file contains something like this initially:
[code]
a
b
c
d[/code]
the code prints out
[code]
a
b
c
[/code]
instantly, but then the cursor keeps on blinking without printing out [b]d[/b]. Even if I append some line, the cursor keeps on blinking all the same. If I don't do anything, at the end of 50 seconds it prints out [b]d[/b], and program terminates. Where am I erring, and how can I rectify it?