blackadder has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks, Greetings.

I have the following simple TK script;
use strict; use warnings; use Tk; use Tk::ProgressBar; my $percent_done=0; my $mw = MainWindow->new(-title => 'Processing'); my $Progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, -blocks => 50, -colors => [0,'blue',100,'blue'], -variable => \$percent_done )->pack(-fill => 'x'); open (LST, "c:\\list.lst")||die "$^E : $!\n"; chomp (my @data=<LST>); my $count = 0; for (@data) { print STDOUT "$_\n"; $percent_done = $count/10; $count++; $mw->update; } MainLoop();
I'm reading a list of remote servers (thousends of 'em!) off a .lst file and printing them on the screen (STDOUT) thats all (at the moment). I would to program a progress bar indicator for this opration. I did a search here on PM and read everything there is to read about progressbars which was very useful. In fact I even have managed to learn it propery but that was some time ago. I have been trying all day to get this thing working, but to no avail (maybe its a mental blockage)...:-(

The problem is; the progress bar indicator reaches the end before completing reading things of my .lst file

Can the Monastery angels enlighten me please on where/what I am doing wrong?

Thanks.
Blackadder

Replies are listed 'Best First'.
Re: Just another TK ProgressBar question!
by Ven'Tatsu (Deacon) on Sep 09, 2004 at 15:15 UTC
    You need to make $percent_done actualy hold the a percentage value, not just the count devided by 10 like so:
    for (@data) { print STDOUT "$_\n"; $percent_done = $count/scalar(@data)*100; $count++; $mw->update; }
Re: Just another TK ProgressBar question!
by PodMaster (Abbot) on Sep 09, 2004 at 15:14 UTC
    Can the Monastery angels enlighten me please on where/what I am doing wrong?
    You forgot how to count :)
    use strict; use warnings; use Tk; use Tk::ProgressBar; my $percent_done=0; my $mw = MainWindow->new(-title => 'Processing'); my $Progress = $mw->ProgressBar( -width => 30, -from => 0, -to => 100, ####### <<<< NOTE THE UPPER LIMIT -blocks => 50, -colors => [0,'blue',100,'blue'], -variable => \$percent_done )->pack(-fill => 'x'); for (1 .. 133)####### <<<< NOTE THIS GOES PAST THE UPPER LIMIT { print STDOUT "$_\n"; $percent_done = $_; $mw->update; select undef, undef, undef, 0.1; } MainLoop();

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Just another TK ProgressBar question!
by zejames (Hermit) on Sep 09, 2004 at 15:27 UTC
    You forgot that the percentage for the progress bar must be a integer between 0 and 100. So using the following code works fine :
    ... my $count = 0; my $total = @data; for (@data) { print STDOUT "$_\n"; $percent_done = $count * 100 / $total; $count++; $mw->update; } MainLoop();

    --
    zejames
      I need to learn how to count,...:-)

      Thanks