]> git.donarmstrong.com Git - term-progressbar.git/blob - examples/powers3
use strict; use warnings; in examples
[term-progressbar.git] / examples / powers3
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Term::ProgressBar 2.00;
6
7 use constant MAX => 100_000;
8
9 my $max = int($ARGV[0] || MAX);
10 my $progress = Term::ProgressBar->new({
11         name => 'Powers',
12         count => $max,
13         remove => 3,
14 });
15 $progress->minor(0);
16 my $next_update = 0;
17
18 for (0..$max) {
19   my $is_power = 0;
20   for(my $i = 0; 2**$i <= $_; $i++) {
21     $is_power = 1
22       if 2**$i == $_;
23   }
24
25   $next_update = $progress->update($_)
26     if $_ > $next_update;
27 }
28 $progress->update($max)
29     if $max >= $next_update;