in reply to running a loop in background...

You need to give Tk the opportunity to deal with updating windows and responding to events. Stick in one or more $MainWindow->Update; inside the various loops. Of course, your MainWindow object may not be named $MainWindow, but you get the idea. You might also want to look into $MainWindow->IdleTasks; which just deals with callsbacks. Both of the above are described in the Tk::Widget POD.

 
perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Re: running a loop in background...
by Anonymous Monk on Sep 12, 2001 at 01:00 UTC
    $mw->update did the trick.....Thanks a lot. but now, of course another problem arises. When the updated file is finally complete, how do I stop 'seek'ing? I tried:
    for(;;) { while(<FH>) { $textbox->insert('end', $_); $textbox->yviewScroll(1, "units"); #print substr($_,0,5); $test = $_; if (substr($_,0,5) eq "\>info") {last;} } #sleep $DELAY; $mw->update; if (substr($test,0,5) ne "\>info") { seek(FH, 0, 1);} } }
    The 'last' function doesn't seem to work. It should be easy, but being new to perl, I'm having trouble. Can anyone help?

      Your problem boils down to the following: You have two loops, and you need to exit both of them from the innermost one. There are multiple ways of doing this (need I say that, with Perl?)

      • Label the outermost loop:
        OUTER: for (;;) { while (<FH>) { # stuff last OUTER if substr($_,0,5) eq "\>info"; } # stuff }
      • Use a flag to tell the outer loop we're done:
        for (my $done = 0; !$done;) { while (<FH>) { # stuff ++$done && last if substr($_,0,5) eq "\>info"; } # stuff }

      By the way, watch the capitalization on the methods. I'm not certain if $mw->update will work; I'm more certain $mw->Update will.

       
      perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'