in reply to Re^2: File::Tail issue..
in thread File::Tail issue..
Searching the docs for "timeout" found a solution.
# 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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: File::Tail issue..
by Anonymous Monk on Mar 20, 2009 at 21:08 UTC | |
by ikegami (Patriarch) on Mar 20, 2009 at 21:32 UTC |