perl进度条

收藏个perl的进度条

  1. #!/usr/bin/perl -w
  2. $n = 27;
  3. for($i=1;$i<=$n;$i++){
  4. proc_bar($i,$n);
  5. select(undef, undef, undef, 0.2);
  6. }
  7. print "\n";
  8.  
  9. sub proc_bar{
  10. local $| = 1;
  11. my $i = $_[0] || return 0;
  12. my $n = $_[1] || return 0;
  13. print "\r\033[36m[\033[33m".("|" x int(($i/$n)*50)).
  14. (" " x (50 - int(($i/$n)*50)))."\033[36m]";
  15. printf("%2.1f%%\033[0m",$i/$n*100);
  16. local $| = 0;
  17. }
1 1