progress bar in command line perl script

后端 未结 3 1224
时光取名叫无心
时光取名叫无心 2021-01-05 15:48

I am trying to print progress in % in command prompt. But it is not working properly.

I want to print the progress as :: Status 10% Completed when 20% will complete

3条回答
  •  我在风中等你
    2021-01-05 16:41

    Small modification to the original code: \n and \r are removed and added autoflush and "\033[G" and \033[J

    $|=1; #autoflush
    
    $count = 0;
    $total = 100;
    while ($count != $total) {
       $count++; 
       $per=($count/$total)*100; 
       print "\033[JStatus: ${per}% Completed."."\033[G"; # man console_codes, ECMA-48 CSI sequences, "CHA"
       sleep 1
     }  
    

提交回复
热议问题