loading/processing animation in perl
Is there a way to display an animation while Perl is process开发者_Python百科ing a file or something else?
Maybe the sequence of | / - | \
(rotating pipe) instead of just printing dots.
Thanks for your help.
The simple rotating pipe can be created using code like this:
#!/usr/bin/perl
use strict;
use warnings;
$|++; # turn off output buffering;
my @chars = qw(| / - \ );
my $i = 0;
print $chars[$i];
while (1) {
sleep 1;
print "\b", $chars[++$i % @chars];
}
For something more complex, take a look at Term::ProgressBar.
Sure, something like this will do it:
perl -e '$|++; foreach $i (0..10) { print "\r", substr("|/-\\", ($i % 4), 1); sleep 1; }'
You can put code like this inside your processing loop to display an appropriate spinner.
精彩评论