DEV Community

Cover image for Show progress with Log::Progress (Perl)
Tib
Tib

Posted on

Show progress with Log::Progress (Perl)

Log::Progess is Perl module to display progress in a configurable manner.

Install Log::Progress

Install as usual with cpanm Log::Progress:

$ cpanm Log::Progress
Fetching http://www.cpan.org/authors/id/N/NE/NERDVANA/Log-Progress-0.12.tar.gz ... OK
Configuring Log-Progress-0.12 ... OK
Building and testing Log-Progress-0.12 ... OK
Successfully installed Log-Progress-0.12
1 distribution installed
Enter fullscreen mode Exit fullscreen mode

At this point you shoule be able to use Log::Progress in your program without any complaints from perl 😁

Report progress

This is what contains my sample below:

  1. Creation of a progress
  2. Configure when to report progress
  3. Set the max and current progress
  4. Actually progress (and let Log::Progress report when appropriate)
use Log::Progress;

my $progress= Log::Progress->new();
$progress->squelch(.1); # Only emit messages every 10%
my $max = 20;
$progress->at(0, $max); # Set current progress and target

for (my $i = 1; $i <= $max; $i++) {
  sleep 1;
  $progress->at($i); # Will not report each time
}
Enter fullscreen mode Exit fullscreen mode

And then I get this progress report:

Log

That's all! 😃
House

Top comments (0)