Here's an example of Tk::IO
You'll have to write a separate perl program to fetch URLs. In this example I faked that part with a simple shell script just as a proof of concept.
#!/usr/bin/perl
# https://perlmonks.org/?node_id=1227829
use strict;
use warnings;
use Tk;
use Tk::IO;
use Tk::ROText;
my (@data1, @data2, @data3, @data4);
my $complete1 = my $complete2 = my $complete3 = my $complete4 = 0;
my $status = 'Ready to Start';
my $mw = MainWindow->new;
$mw->Button(-text => 'Load', -command => \&startload,
)->pack;
$mw->Label(-textvariable => \$status,
)->pack;
$mw->Button(-text => 'Exit', -command => sub{$mw->destroy},
)->pack(-side => 'bottom');
$_ = $mw->ROText( -width => 40,
)->pack(-side => 'left') for my ($t1, $t2, $t3, $t4);
MainLoop;
sub startload
{
$status = 'Started';
child( \@data1, \$complete1, 'one', 'sleep 1; echo data one', $t1 );
child( \@data2, \$complete2, 'two', 'sleep 3; echo data two', $t2 );
child( \@data3, \$complete3, 'three', 'sleep 4; echo data three', $t
+3 );
child( \@data4, \$complete4, 'four', 'sleep 2; echo data four', $t4
+);
}
sub common
{
$complete1 && $complete2 && $complete3 && $complete4 or return;
$status = 'All Completed';
# do final processing here #####################
}
sub child
{
my ($refdata, $refcomplete, $message, $command, $rotext) = @_;
@$refdata = ();
$$refcomplete = 0;
$rotext->delete('1.0' => 'end');
Tk::IO->new(
-linecommand => sub {push @$refdata, shift},
-childcommand => sub {
$$refcomplete = 1;
$status = "$message completed";
$rotext->insert(end => join '', @$refdata);
common();
},
)->exec($command);
}
There are a couple other examples of Tk::IO on this site, you can search for them if you want.
|