in reply to Monitoring a file which is constantly being written to.

If I were writing this I'd probably use:

open T, '-|', 'tail', '-f', $file; while (<T>) {}

Note that, barring serious system failure or ^C, this loop will never end.

If you can't stand that, then you should just leave the file open, then once in a while (between sleeps, perhaps) call:

seek FILE, 0, 1; # clear EOF condition while (<FILE>) {}

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re: Re: Monitoring a file which is constantly being written to.
by creutzfeldt (Novice) on Jun 20, 2003 at 23:42 UTC
    I've run into a situation where data was coming in real time
    and couldn't be ignored, but also needed to be displayed
    and stored in database.

    Writing and reading a file constantly was too "messy" in
    terms of possible conflicts from two different programs -
    even with lockfiles.

    Perls Interprocess Communication (IPC) solved the problem.

    See:

    http://www.perldoc.com/perl5.6/pod/perlipc.html

    CPAN also many variations in IPC (222 hits on "IPC" alone).

Re: Re: Monitoring a file which is constantly being written to.
by devslashneil (Friar) on Jun 20, 2003 at 03:38 UTC
    Thanks for your reply.

    Almost as soon as i clicked "submit" on this post i thought of the tail approach, however i would be suprised if there is not a module which can handle this more efficiantly than i can write?

    - Neil

      You could take a look at File::Tail.

      I doubt that it is much more efficient than chips seek approach as it uses that same method, but a quick browse of the source shows that it does a lot more besides.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


      "File::Tail - Perl extension for reading from continously updated files"

      This should do nicely ;)

      - Neil