In your code above, the only place you can inject an update, is after each file is retreived
However, now that you are getting into GUI programming, you will start to become aware of the "better methods" for doing the tasks. The "get" method of LWP is easy for commandline use, but dig into the docs, and you will find something which gives more control, for gui progress tracking. For instance:foreach my $file (@pics) { &get_url($file); $label->configure(-text => "$file finished"); $label->update; }
Now you can feed info to a progressbar, or whatever. Other libs have similar features. CURL and libCURL are similar to LWP, and also have the more detailed ways of watching the "chunks of data" as they come in.#!/usr/bin/perl -w use strict; use LWP::UserAgent; # don't buffer the prints to make the status update $| = 1; my $ua = LWP::UserAgent->new(); my $received_size = 0; my $url = 'http://www.cpan.org/authors/id/J/JG/JGOFF/parrot-0_0_7.tgz' +; print "Fetching $url\n"; my $request_time = time; my $last_update = 0; my $response = $ua->get($url, ':content_cb' => \&callback, ':read_size_hint' => 8192, ); print "\n"; sub callback { my ($data, $response, $protocol) = @_; my $total_size = $response->header('Content-Length') || 0; $received_size += length $data; # FIXME: write the $data to a filehandle or whatever should happen # with it here. my $time_now = time; # this to make the status only update once per second. return unless $time_now > $last_update or $received_size == $total_s +ize; $last_update = $time_now; print "\rReceived $received_size bytes"; printf " (%i%%)", (100/$total_size)*$received_size if $total_size; printf " %6.1f/bps", $received_size/(($time_now-$request_time)||1) if $received_size; }
In reply to Re: TK subroutine status
by zentara
in thread TK subroutine status
by K_M_McMahon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |