打印具有实时更新的脚本的进度条

时间:2012-11-07 16:09:23

标签: perl

在我的脚本中,我检查元素的存在与我已经拥有的一组数据的比较,我多次这样做,因此进度条。

这就是我现在正在做的事情

### A loop which is done multiple times ### 

my $i =1;
my $page = 50;
while ($i <= $page)    
{

##### Part where I print my progress bar ######
print "\rProgress:[";
my $completed =($i/$page)*100;
$completed = ceil($completed);
my $l= $completed;
while ($l>0){
    print "#";
    $l--;
}   
my $remaining = 100-$completed;
while ($remaining>0){
    print " ";
    $m--;
} 
print "] ";
print $completed . "% Complete";


######### Part where I check and keep count #############
foreach (@each_job) 
{
    my $temp = $_;
    # Count number of jobs that exist with my set
    if ($job{"$temp"} == 1) 
    { 
        $does_exist++ ;
        ## print "\n Exists - $does_exist"; #Confused for this print
    }
    else 
    {
        $does_not_exist++;
        ## print "\n Does not exist - $does_not_exist"; #Confused for this print
    };
    };
    $i++;
}

所以我目前得到的是像

Progress:[################################################                                                    ] 48% Complete

工作正常,并逐页显示进度条。 但我想要的是这样的事情 -

Progress:[################################################                                                    ] 48% Complete
Exists - 3
Does Not Exist - 5

在同一地点不断更新(使用\r)。 有人能帮我吗 ?

1 个答案:

答案 0 :(得分:0)

使用curses库为您处理所有转义码rigamarole,让您可以直接更新屏幕区域。

从这个CPAN search for curses modules开始。