Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Term::ProgressBar

by crenz (Priest)
on Jul 13, 2003 at 21:07 UTC ( #273825=modulereview: print w/ replies, xml ) Need Help??

Item Description: Allows you to easily add progress bars to your command-line utilities

Review Synopsis: I love it. Term::ProgressBar is a nice shiny black box that you can add to your CLI tool and that just works.

I have a number of utilities written in Perl that take a while to complete -- e.g. scaling a large number of digital images. It would be nice to know when the task is finished, but usually the script is too small to warrant extravagant code for monitoring progress.

Fortunately, there's Term::ProgressBar. It lets you add a fancy wget/scp-style progress bar to your own ap, with only a few lines of code. Martyn J. Pearce has really made an effort to make things easy for us: For basic usage, you just need to call one function to set up the progress bar and another one to update it. He even threw in ETA (estimated time of arrival) calculation.

Let's look at some code. I like the ETA display, so I'm making it a bit more complicated than the very basic usage (two more lines added, horrors!). This is taken from my image scaling script:

use Term::ProgressBar; my $progress = Term::ProgressBar->new({name => 'Scaling images', count => scalar @imgfiles, ETA => 'linear'}); # update ETA once per second at most $progress->max_update_rate(1); foreach (@imgfiles) { perform_imaging_ops($_); $progress->update(); }

The output looks somewhat like this (note: I shortened the output here to make it fit on one code line):

crenz@tiffy:~ > scaleimages /my/directory Scaling images: 19% [========= + ]ETA 23:35

I'm using a German locale, so the script displays 23:35 instead of 11:35pm -- just in case you're wondering. When the estimated time needed is short, the display automatically changes:

Scaling images: 92% [============================================ + ]5m14s Left

I'm using the module on Mac OS X, but it should work on all standard Unix terminals. Not sure whether it works on Windows.

Comment on Term::ProgressBar
Select or Download Code
Re: Term::ProgressBar
by bruno (Friar) on Aug 17, 2008 at 04:52 UTC
    ++ For the review.

    I would also like to add that the module Smart::Comments also supports progress bars, like so:

    use Smart::Comments; foreach (@array) { ### Evaluating... done # do something... }
    When the program enters the loop, it will show the comment and the dots will add until they reach the "done" word. It also supports many other formats.

    I've read somewhere that its use was not recommended because, unlike the approach reviewed in the root node, it does source filtering. Although it might not be a guarantee of anything, I personally used it for my "progress bar" needs without a problem.

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://273825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-09-20 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (155 votes), past polls