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

I have a Perl/Tk application that puts out progress messages, however, all messages seem to be buffered; i.e: they all come out at once. Is there a way to make the messages appear as they are generated? Thanks; Marty
A mainframe programmer trying to do Perl!

Replies are listed 'Best First'.
Re: Perl/Tk Message buffering
by SuicideJunkie (Vicar) on Dec 15, 2010 at 15:58 UTC

    If you mean buffered messages to the console, then $| is the special variable you're looking for.

    If you want text boxes in your gui to update while doing a long operation, then the Tk DoOneEvent() function will help.

      This is a snippet of the code I was referring to. I was just starting to look at DoOneEvent(), but it did not seem to help. if ($progress_count eq '500') { print "Records processed : $record_1_count \n"; $txt -> insert('end',"Records processed : $record_1_count \n"); $progress_count = 0; DoOneEvent(); }
      A mainframe programmer trying to do Perl!

        Note: Use <code></code> tags around your code to keep it legible.

        One single event isn't enough to react to updates and repaint the whole window among responding to all the minor events Windows may throw at your app. Put the DoOneEvent inside the loop you didn't show, rather than the if. That way, you'll interleave small bits of GUI action between record processing, and they'll both share the CPU.

        Also, look up the parameters for DoOneEvent to find the best set of options for your situation. Not waiting if there are no pending events, for example.

        $txt->update
        Cheers, Christoph
Re: Perl/Tk Message buffering
by MidLifeXis (Monsignor) on Dec 15, 2010 at 15:57 UTC

    See the documentation on autoflush.

    Update: Hmm, Tk application - not sure if this will work (I have not yet had an opportunity to write Tk), but it is worth a try.

    --MidLifeXis