The basic usage is to call a subroutine, once every loop, through your long process. Like:
#!/usr/bin/perl
use strict;
use warnings;
my $spinner_pos = 0;
sub spin {
my $spinner = '|\-/';
print STDERR substr($spinner, $spinner_pos++%length($spinner), 1)."\r"
+;
}
while (1) {
qx(cat /etc/termcap); #simulate doing important stuff
spin();
}
So you have to design your application, and progress indicator together. There is no 1 "foolproof way" to use them. So what type of proram are you running? If you show us, we can help you with placing an indicator somewhere in the code. It's "fun" and educational to experiment yourself.
Take the snippets you've received here, and play with them.
You can't break anything. You will get the idea of how they work eventually.
In some "event driven programs" like Tk, you can make your
indicator an object, and just do things like
$progressindicator->start;
$progressindicator->stop;
here is another widely used style of indicator used by wget
#!/usr/bin/perl
$|=1;
do{ print progress_bar( $_, 100, 25, '=' ); sleep 1 } for 1..100;
sub progress_bar {
my ( $got, $total, $width, $char ) = @_;
$width ||= 25;
$char ||= '=';
$num_width = length $total;
sprintf "|%-${width}s| Got %${num_width}s bytes of %s (%.2f%)\r",
$char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/$
+total;
}
I'm not really a human, but I play one on earth.
flash japh
|