Perl - printing progress on same line.
I have a script that prints out an iteration of numbers. The problem is the printed output scrolls. Exa:
123211 packets sent. 123212 packets sent. 123213 packets sent. 123214 packets sent. 123215 packets sent. Simple code exa: $iter++; print "$iter packets sent.\n" if $verbose; **** What I want instead is for only a single line to be printed but the number on that single line to increment ( no scrolling ). I've seen this before but can't find my example, so hoping someone can help me and/or point me to a web page that might have further info on it. Thanks, |
\n will take the cursor on to the next line, scrolling as necessary
\r will take you to the start of the current line: Code:
$iter++; |
That's what I was looking for. Thanks!
|
This doesn't work as expected if the line being printed is longer than the width of the terminal.
|
Quote:
you post a solution to the THAT problem? Cheers, Tink |
Since we seem to be getting a lot of replies to zombie threads lately, perhaps it is appropriate to mention that the Zero-Reply Threads pseudo-forum exists. It almost guarantees that the threads founds are current.
--- rod. |
There is no real solution that I know of.
You can use GetTerminalSize like this: use Term::ReadKey; ($width) = GetTerminalSize(); # don't forget the parens round $width and then only print out out the first $width characters of a string. You can't print something out over two lines and then overwrite both lines. |
There is a Perl variable ... see perldoc perlvar and look up "$|" ... that's dollar-sign vertical-bar.
This controls whether output is "buffered" pending the next newline character. |
All times are GMT -5. The time now is 09:20 AM. |