in reply to Associating filehandles with Perl::Tk widgets?

Usually you just open the file, and as you loop thru it, insert each line into the text widget. I just slapped together this FORMAT, which is written to a string, then the string is inserted. What are you trying to do? Tail a file or something? Usually with the text widget, you use it's tags mechanism to format your lines. I think you are approaching the problem the wrong way, to put a format in a Tk Text widget.
#!/usr/bin/perl my $foo = ''; open FH, '+>', \$foo or die $!; format FH_TOP = WHO COMMAND OUTPUT USER TERMINAL DATE & TIME LOCATION ----------------------------------------------------------- . my @who_output= `who`; foreach my $line (@who_output) { my ($userid,$terminal,$month,$day,$time,$location) = split(/\s+/,$line +); chomp $location; format FH = @<<<<<<< @<<<<<<<<< @<<< @<< @<<<<< @<<<<<<<<<<<< $userid $terminal $month $day $time $location . write FH; } #print "$foo\n"; use Tk; my $top = new MainWindow; my $txt = $top->Scrolled("Text")->pack; $txt->insert('end', "$foo\n") ; MainLoop;
but here is a way to tie stdout to the text widget, but usually you would setup a fileevent ( select ) on a filehandle, then in the fileevent's callback, you insert into the text widget, as you read them.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $tx = $mw->Text()->pack(); tie *STDOUT, 'Tk::Text', $tx; $mw->repeat(1000, \&tick); MainLoop; my $count; sub tick { ++$count; print "$count\n"; }

I'm not really a human, but I play one on earth CandyGram for Mongo