[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Completely OT: Perl progress bar/meter



On Sat, Jun 29, 2002 at 04:21:21AM -0500, Alex Malinovich wrote:
> I've been thinking about this for a while, and even though it's not
> really important, I would like to get it in. I've got a script which, on
> average, processes about 10,000 files each time it's run, taking a
> minute or two to finish. Since having no feedback is not an option, I
> opted to have a "File X of Y finished..." line printed after each file.
> While this gives the user feedback, it also gives him 10,000 lines of
> useless text on the terminal. Any ideas on how to re-write a line
> repeatedly and quickly in Perl?

If you haven't yet printed the newline, then just print a carriage
return ("\r") and you'll go back to the start of the line. Be sure to
print enough spaces to completely overwrite the previous text if what
you're printing is shorter, and be sure to set the $| variable to 1 so
that text is output even when you haven't yet printed the "\n".

> As far as I know Perl can't do screen refreshes,

That's up to the terminal, and if you want a full-screen refresh you can
do that too. As long as the terminal has some ANSI capabilities (most
do), you can print "\e[H\e[J" to clear the screen, or just "\e[H" if you
simply want to move the cursor back to the home position.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: