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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.