The script reads the lines from the file, here's the code:
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
open my $fh, '<', 'input.txt' or die "Can't open file: $!";
my $cv = AE::cv;
my $timer = AE::timer 0, 10, sub {
printf "TELL: %s EOF: %s\n", tell $fh, eof $fh;
print while <$fh>;
};
$cv->recv;
If I add lines through cat, then the script reads the new lines. But if I edit the file through a vim editor, then the script does not see any new lines in the file and issues an EOF. Why does the script behave this way and do not see new lines?
Output of the script:
$ perl test.pl
TELL: 0 EOF:
row_1
row_2
row_3
TELL: 18 EOF: 1
TELL: 18 EOF: 1
TELL: 18 EOF:
row_4
TELL: 24 EOF:
row_5
TELL: 30 EOF: 1
TELL: 30 EOF: 1
TELL: 30 EOF: 1
TELL: 30 EOF: 1
The initial content of the input.txt:
row_1
row_2
row_3
Added via cat:
$ cat >> input.txt
row_4
row_5
Added via vim:
$ vim input.txt
row_6
row_7