Term-Sk
view release on metacpan or search on metacpan
lib/Term/Sk.pm view on Meta::CPAN
At any time, after Term::Sk->new(), you can query the number of ticks (i.e. number of calls to
$ctr->up or $ctr->down) using the method 'ticks':
use Term::Sk;
my $ctr = Term::Sk->new('%6c', {freq => 's', base => 0, target => 70});
for (1..4288) {
$ctr->up;
}
$ctr->close;
print "Number of ticks: ", $ctr->ticks, "\n";
This example uses a simple progress bar in quiet mode (nothing is printed to STDOUT), but
instead, the content of what would have been printed can now be extracted using the get_line() method:
use Term::Sk;
my $format = 'Ctr %4c';
my $ctr = Term::Sk->new($format, {freq => 2, base => 0, target => 10, quiet => 1});
my $line = $ctr->get_line;
$line =~ s/\010/</g;
print "This is what would have been printed upon new(): [$line]\n";
for my $i (1..10) {
$ctr->up;
$line = $ctr->get_line;
$line =~ s/\010/</g;
print "This is what would have been printed upon $i. call to up(): [$line]\n";
}
$ctr->close;
$line = $ctr->get_line;
$line =~ s/\010/</g;
print "This is what would have been printed upon close(): [$line]\n";
Here are some examples that show different values for option {num => ...}
my $format = 'act %c max %m';
my $ctr1 = Term::Sk->new($format, {base => 1234567, target => 2345678});
# The following numbers are shown: act 1_234_567 max 2_345_678
my $ctr2 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9,999}});
# The following numbers are shown: act 1,234,567 max 2,345,678
my $ctr3 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9'99}});
# The following numbers are shown: act 1'23'45'67 max 2'34'56'78
my $ctr4 = Term::Sk->new($format, {base => 1234567, target => 2345678, num => q{9}});
# The following numbers are shown: act 1234567 max 2345678
my $ctr5 = Term::Sk->new($format, {base => 1234567, target => 2345678,
commify => sub{ join '!', split m{}xms, $_[0]; }});
# The following numbers are shown: act 1!2!3!4!5!6!7 max 2!3!4!5!6!7!8
=head1 DESCRIPTION
=head2 Format strings
The first parameter to new() is the format string which contains the following
special characters:
=over
=item characters '%d'
a revolving dash, format '/-\|'
=item characters '%t'
time elapsed, format 'hh:mm:ss'
=item characters '%b'
progress bar, format '#####_____'
=item characters '%p'
Progress in percentage, format '999%'
=item characters '%c'
Actual counter value (commified by '_'), format '99_999_999'
=item characters '%m'
Target maximum value (commified by '_'), format '99_999_999'
=item characters '%k'
Token which updates its value before being displayed. An example use
of this would be a loop wherein every step of the loop could be
identified by a particular string. For example:
my $ctr = Term::Sk->new('Processing %k counter %c',
{base => 0, token => 'Albania'});
foreach my $country (@list_of_european_nations) {
$ctr->token($country);
for (1..500) {
$ctr->up;
## do something...
}
};
$ctr->close;
You can also have more than one token on a single line. Here is an example:
my $ctr = Term::Sk->new('Processing %k Region %k counter %c',
{base => 0, token => ['Albania', 'South']});
foreach my $country (@list_of_european_nations) {
$ctr->token([$country, 'North']);
for (1..500) {
$ctr->up;
( run in 1.177 second using v1.01-cache-2.11-cpan-71847e10f99 )