On Jun 10, 2014, at 2:59 PM, Kenneth Wolcott wrote:

> Hi All;
> 
> how to create a text progress status line that updates on the same line in 
> Perl?
> 
> I know that this questions is probably not well-posed, but I hope you
> get what I'm after.
> 
> I'd like to do what application installers do, describing the status,
> updating the status occasionally, but on the same line overwriting
> what was there earlier.
> 
> Do I need to use the hex or oct form of the backspace (octal 010) for
> each character that I want to overwrite?

Quick answer:

1. Use print (not say),
2. Turn on autoflushing ($|++),
3. Put a carriage return character ("\r") at the beginning of the line,
4. Don't put a new line ("\n") at the end of the line, and 
5. Either use the same, fixed number of characters each time or add spaces at 
the end of short lines to erase any characters left over from a previous line.

Check this out:

perl -e '$|++;for (0..20) { $x=q(=)x$_;$y=q( )x(20-$_); print 
qq(\r$x$y);sleep(1);}' 
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to