GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Term::ProgressBar::Simple(3) User Contributed Perl Documentation Term::ProgressBar::Simple(3)

Term::ProgressBar::Simple - simpler progress bars

    # create some things to loop over
    my @things = (...);
    my $number_of_things = scalar @things;

    # create the progress bar object
    my $progress = Term::ProgressBar::Simple->new( $number_of_things );

    # loop
    foreach my $thing (@things) {

        # do some work
        $thing->do_something();

        # increment the progress bar object to tell it a step has been taken.
        $progress++;
    }

    # See also use of '$progress += $number' later in pod

Progress bars are handy - they tell you how much work has been done, how much is left to do and estimate how long it will take.

But they can be fiddly!

This module does the right thing in almost all cases in a really convenient way.

Lots - does all the best practice:

Wraps Term::ProgressBar::Quiet so there is no output unless the code is running interactively - lets you put them in cron scripts.

Deals with minor updates - only refreshes the screen when it will change what the user sees so it is efficient.

Completes the progress bar when the progress object is destroyed (explicitly or by going out of scope) - no more '99%' done.

    # Either...
    my $progress = Term::ProgressBar::Simple->new($count);

    # ... or
    my $progress = Term::ProgressBar::Simple->new(
        {
            count => $count,               #
            name  => 'descriptive text',
        }
    );

Create a new progress bar. Either just pass in the number of things to do, or a config hash. See Term::ProgressBar for details.

    $progress++;

Incrementing the object causes the progress display to be updated. It is smart about checking to see if the display needs to be updated.

    $progress += $number_done;

Sometimes you'll have done more than one step between updates. A good example is processing logfiles, where the time taken is relative to the size of the file. In this case code like this would give a better feel for the progress made:

    # Get the total size of all the files
    my $total_size = sum map { -s } @filenames;

    # Set up object with total size as steps to do
    my $progress = Term::ProgressBar::Simple->new($total_size);

    # process each file and increment by the size of each file
    foreach my $filename (@filenames) {
        process_the_file($filename);
        $progress += -s $filename;
    }

    $progress->message('Copying $filename');

Output a message. This is very much like print, but we try not to disturb the terminal.

Term::ProgressBar & Term::ProgressBar::Quiet

Not all operators are overloaded, so things might blow up in interesting ways. Patches welcome.

Martyn J. Pearce for the orginal and great Term::ProgressBar.

Leon Brocard for doing the hard work in Term::ProgressBar::Quiet, and for submitting a patch with the code for "+="..

YAPC::EU::2008 for providing the venue and coffee whilst the first version of this module was written.

Edmund von der Burg "<evdb@ecclestoad.co.uk>".

<http://www.ecclestoad.co.uk/>

There are no tests - there should be. The smart way would be to trap the output and check it is right.

Copyright (c) 2008, Edmund von der Burg "<evdb@ecclestoad.co.uk>". All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2009-02-24 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.