in reply to running a loop in background...
There is Tk::fileevent, which gets you most of the way there, but doesn't have a built-in mechanism to re-seek for the 'tail -f' functionality you need. Basically the fileevent fires on eof, so you would have to turn the fileevent on and off. Ick.
My last idea was to use Tk::After's repeat() functionality. Seems to work for me. This short example creates a listbox, and does something of a "tail -f /tmp/testfile" on it while still allowing other events to fire. (You can type in the entry box to verify this)
Here you go:
Update: Depending on how fast the text is streaming, you may want to call Tk::DoOneEvent(0) in the while(<$FILE>) loop.#!/usr/bin/perl use IO::File; use IO::Select; use Tk; my $FILE=IO::File->new("/tmp/testfile") or die; my $SEL=IO::Select->new(); $SEL->add($FILE); my $mw=Tk::MainWindow->new(); my $list=$mw->Listbox->pack(); my $entry=$mw->Entry->pack(); $list->repeat(500, sub { if ($SEL->can_read(0)) { while(<$FILE>) { chomp; $list->insert(end,$_); $list->see(($list->size)-1); } seek(FILE,0,1); } }); MainLoop;
|
|---|