Is there a way to display an animation while Perl is processing 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With