Good day seminarians. I have a script that processes a number of large JSON files and I would like to have a bar to track progress for each file. I've tried to implement one, as shown here on a pseudo-version of my code (to avoid distractions) like so:
use strict;
use feature ':5.10';
use Term::ProgressBar;
my @files = qw(30 50);
foreach my $f (@files) {
my $max = $f;
my $progress = Term::ProgressBar->new({name => 'Processed', count
+=> $max, remove => 1, ETA => 'linear'});
$progress->max_update_rate(1);
$progress->minor(0);
my $next_update = 0;
foreach my $i (0..$max) {
sleep 1; # represents stuff my script is actually processing
$next_update = $progress->update($_) if $_ >= $next_update;
}
$progress->update($max) if $max >= $next_update;
}
Instead of filenames the script actually uses I've just given it a couple of counts for the inner loop. In place of the actual processing done on the file contents I've included a sleep.
I'm doing something wrong because the progress bar advances one step and that's it until it completes. To be honest the example code given in the module docs is a little hard for me to follow. I don't understand what is setting $_ so maybe I'm not doing something with that that I shouldbe doing.
Can anyone say what I'm doing wrong?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.