I think the problem is once you've done the first $line=<TAIL> it's too late. Here's what I wrote that DOES work correctly and will not exit the loop, but as I said I'm not proud of it ;):
#!/usr/bin/perl -w
use Time::HiRes;
$SIG{"ALRM"}=\&sigAlarm;
my $interval=1;
my $uInterval=$interval*10**6;
Time::HiRes::ualarm($uInterval, $uInterval);
my $logname='xyz';
open TAIL, "tail -f $logname|" or die "couldn't open $logname";
while (1)
{
while(1)
{
if (eof(TAIL))
{
printf "EOF: %d\n", eof(TAIL);
$line=<TAIL>;
next;
}
last if !($line=<TAIL>);
print $line;
}
print "Fell through...\n";
}
sub sigAlarm
{
print "alarm\n";
}
I also wonder if doing that eof() test at the beginning go throw me into an infinite loop under some conditions, but as so far this seems to be ok for now.
-mark |