how to read tail -F command output in perl

Hi All,

How I will read the output of the tail -F command in perl.

I have text file with below contains

file1.txt

1
2
3
4

$running=1;
sub openLog($)
{
  (my $log) = @_;
  local *LOG;
  unless( open(LOG,$log." |") ) { print "unable to launch log: $!\n"; return 0; }
  print "logging started with ".$log."\n";
  return *LOG{IO};
}

while($running) {
my $pipe = openLog('tail -F file1.txt');
while (<$pipe>) { print $_ ;}
sleep 30;
}

After running the above script I am getting the below output and I am sending this output to the another server.

1
2
3
4

After that I have modified the file1.txt and added the below data.

file1.txt

1
2
3
4
5 #new data
6 #new data
7 #new data

I am getting the below output

1
2
3
4
5 #new data
6 #new data
7 #new data

How I will get below output after modifying the file1.txt , so I can send this output to the another server instead of sending again previous data

5 #new data
6 #new data
7 #new data

Please help me ..............

tail -fworks by closing and reopening the file.
there is no special magic involved.

you will have to do the same.
read the file.
save the position in the file with tell
close the file
sleep
then when you reopen it do a seek to the same spot.

this won't work of course if the top of the file has been trimmed in the interim.

perldoc -f seek
perldoc -f tell