]> git.donarmstrong.com Git - term-progressbar.git/blob - examples/powers4
use strict; use warnings; in examples
[term-progressbar.git] / examples / powers4
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Term::ProgressBar 2.00;
6
7 use constant MAX => 1_000_000;
8
9 my $max = int($ARGV[0] || MAX);
10 my $progress = Term::ProgressBar->new({
11         name => 'Powers',
12         count => $max,
13         ETA => 'linear',
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 sleep 1
25 if $_ % 4 == 0;
26
27   $next_update = $progress->update($_)
28     if $_ > $next_update;
29 }
30 $progress->update($max)
31     if $max >= $next_update;