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

I am attempting to break up a text file into each word so as to then have it displayed within a Tk widget after a time delay. Unfortunately I can't seem to get it to do this using a while loop because it waits until the while loop finishes before it creates the widget. If anyone can help I would really appreciate it (I'm still really new to Perl).
#!/usr/bin/perl -w use strict; use Tk; my $mw = new MainWindow; my $rec1 = $mw->Canvas(-height => "90", -width => "500")->pack(); $rec1->createRectangle(1,1,500,90, -fill => "black"); my $txt_tag = $rec1->createText(250,45, -justify => "center", -fill => "yellow", -font => "times 50", ); open(FILE, "sip.txt"); while ( <FILE> ) { push my @lines, [ split ]; for my $i ( 0 .. $#lines ) { for my $j ( 0 .. $#{$lines[$i]} ) { # $word = $lines[$i][$j]; $mw->after(200); print "$lines[$i][$j] "; $rec1->dchars($txt_tag,0); $rec1->insert($txt_tag,0,$lines[$i][$j]); } } } MainLoop;

Replies are listed 'Best First'.
Re: while loops and perl/Tk
by TheoPetersen (Priest) on Apr 16, 2001 at 23:26 UTC