Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update a progress display on a Perl command-line application?

I have a little Perl script (On Windows) that checks some files for me as an aid to my day-to-day business. At the moment it prints out something like...

0%
25%
50%
75%
Complete

But I can remember scripts I've used in the past that didn't print progress on a line-by-line basis, but which updated the output on the display, presumably by moving the cursor back and over-printing what was there.

Anyone know what magic is required? Portability isn't important to me, the script is quite disposable.

like image 367
izb Avatar asked Nov 10 '08 09:11

izb


2 Answers

You could use curses and make a nice progress bar.

EDIT: Or do something like this:

print "#####                                 [ 10%]\r";
# Do something
print "##########                            [ 20%]\r";
# Do something else
print "###############                       [ 30%]\r";
# Do some more
# ...
# ...
# ...
print "##################################### [100%]\n";
print "Done.\n";
like image 68
daniels Avatar answered Sep 28 '22 07:09

daniels


In addition to the other answers, \r will go back to the beginning of the current line

like image 38
1800 INFORMATION Avatar answered Sep 28 '22 07:09

1800 INFORMATION