From: Gabor Szabo Date: Tue, 29 Nov 2011 15:49:13 +0000 (+0200) Subject: copy two examples from the docs to the eg directory X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=commitdiff_plain;h=33e231ca939cbe1231c82a60d2ba7f8461b659e3 copy two examples from the docs to the eg directory --- diff --git a/eg/simple_use.pl b/eg/simple_use.pl new file mode 100644 index 0000000..6d57747 --- /dev/null +++ b/eg/simple_use.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Term::ProgressBar 2.00; + +use constant MAX => 100_000; + +my $progress = Term::ProgressBar->new(MAX); + +for (0..MAX) { + my $is_power = 0; + for(my $i = 0; 2**$i <= $_; $i++) { + $is_power = 1 + if 2**$i == $_; + } + + if ( $is_power ) { + $progress->update($_); + } +} diff --git a/eg/smooth_bar.pl b/eg/smooth_bar.pl new file mode 100644 index 0000000..befae9a --- /dev/null +++ b/eg/smooth_bar.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Term::ProgressBar 2.00; + +my $max = shift || 100; + +my $progress = Term::ProgressBar->new($max); + +for (0..$max) { + my $is_power = 0; + for(my $i = 0; 2**$i <= $_; $i++) { + $is_power = 1 + if 2**$i == $_; + } + + $progress->update($_) +} diff --git a/lib/Term/ProgressBar.pm b/lib/Term/ProgressBar.pm index f1ed1dc..84ed9b8 100644 --- a/lib/Term/ProgressBar.pm +++ b/lib/Term/ProgressBar.pm @@ -75,6 +75,8 @@ bar for the same width. } } +see eg/simle_use.pl + Here is a simple example. The process considers all the numbers between 0 and MAX, and updates the progress bar whenever it finds one. Note that the progress bar update will be very erratic. See below for a smoother example. @@ -97,6 +99,8 @@ distribution set (it is not installed as part of the module). $progress->update($_) } +See eg/smooth_bar.pl + This example calls update for each value considered. This will result in a much smoother progress update, but more program time is spent updating the bar than doing the "real" work. See below to remedy this. This example does