开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜