Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am making a TK/Perl script to run an external program. The external program produces a text file that updates the status of the operation. How can continuously show this file on screen while it is being updated by the external program?

Replies are listed 'Best First'.
Re: printing lines of a changing document
by chromatic (Archbishop) on Sep 07, 2001 at 04:36 UTC
Re: printing lines of a changing document
by gellor (Novice) on Sep 07, 2001 at 01:17 UTC
    The Perl Cookbook covers the problem of watching a constantly growing file.

    Their suggested solution is along the lines of:

    (re-constructed from memory and some of my scripts)

    open (FH, "filename") or die "Unable to open file: $!"; $DELAY = 5; for(;;) { while(<FH>) { #do stuff here } sleep $DELAY seek(FH, 0, 1); }
    The PCB also mentions that IO::Handle but I don't have an example of that quickly availible.

    I'll leave the display portion for you or another monk as I don't have any TK experience.

    Update: Added the seek line that should have always been there...not sure how I missed it in preview.