命令行perl脚本中的进度条 [英] progress bar in command line perl script
本文介绍了命令行perl脚本中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在命令提示符下以%打印进度.但是它不能正常工作.
I am trying to print progress in % in command prompt. But it is not working properly.
我要将进度打印为::状态10%已完成 20%完成时将显示Status 20%Completed 在同一个地方,不在新行中.你能帮我吗?
I want to print the progress as :: Status 10% Completed when 20% will complete it will show Status 20% Completed in that same place not in new line. Could you please help me.
代码::
$count++;
$per=($count/$total)*100;
print "\nStatus: $per Completed.\r";
sleep 1;
推荐答案
您可以执行以下操作:
use strict;
use warnings;
use Time::HiRes qw(usleep);
local $| = 1;
my @nums = 1 .. 20;
foreach my $c (@nums) {
print "$c";
usleep(100000);
print ("\b" x length($c));
}
print "\n";
这篇关于命令行perl脚本中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文