in reply to Re: File::Tail issue..
in thread File::Tail issue..

I think the problem is  read doesn't return. Because if it had retured the program would have terminated(becuase it must have exited the loop). But the program never ends. It does what File::Tail should be doing but just doesn't update it with the new file's contents.

Replies are listed 'Best First'.
Re^3: File::Tail issue..
by ikegami (Patriarch) on Mar 20, 2009 at 18:03 UTC

    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; } }
      Thanks ikegami. That worked neat. But I'm still wary of this disclaimer in the docs:

      "Note: Select functionality was added in version 0.9, and it required some reworking of all routines. ***PLEASE*** let me know if you see anything strange happening."
      Anyways thanks for helping me out. I'm going forward with this :)
        All routines had to be reworked, so if you're using a version that's been released since Nov 1998 (over a decade ago), you're affected by this whether you use select or not.