# Check for new File::Tail object every $timeout seconds.
my $timeout = 60;
for (;;) {
my (undef, undef, @pending) =
File::Tail::select(undef, undef, undef, $timeout, $file);
for (@pending) {
my $line = $_->read();
print $line;
}
}
Update: You could even simplify your signal handler (always a good thing) and your code in general as follows:
use File::Tail;
# Check for new File::Tail object every $timeout seconds.
my $timeout = 60;
my $qfn = $ARGV[0];
my $new = 1;
my $changed = 0;
my $tail;
$SIG{INT} = sub { $changed = 1 };
for (;;) {
if ($changed) {
$changed = 0;
open(my $fh, '<', '/tmp/filename')
or die("Cannot open file: $!\n");
chomp( $qfn = <$fh> );
$new = 1;
}
if ($new) {
$new = 0;
$tail = File::Tail->new(
name => $qfn,
maxinterval => 3,
adjustafter => 2,
tail => -1,
);
}
my (undef, undef, @pending) =
File::Tail::select(undef, undef, undef, $timeout, $tail);
for (@pending) {
my $line = $_->read();
print $line;
}
}
|