Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Controlling already printed text to console.

by frozenwithjoy (Curate)
on Aug 02, 2012 at 06:47 UTC ( #984954=note: print w/ replies, xml ) Need Help??


in reply to Controlling already printed text to console.

Is this type of output what you are talking about?

#!/usr/bin/env perl use strict; use warnings; $| = 1; my $i=0; while ( $i < 10 ) { print "$i\r"; $i++; sleep 1; } while ( $i >= 0 ) { print " " x 80 . "\r"; print "$i\r"; $i--; sleep 1; } print "\n";

This script counts up from 0 to 10 (and back to 0) with each number replacing the previous. It does this by using the carriage return character (\r) instead of the new line character (\n), which is essentially a carriage return followed by a line-feed. The $| = 1 makes the output autoflush. One thing to keep in mind is that printing a string that is shorter than the previous will result in artifacts of the previous longer string. You can get around this by printing several spaces with something like: print " " x 80 . "\r";

note: If you want to keep the final output, be sure to print a \n when you are all done or it will get over-written by the next (unrelated) output.


Comment on Re: Controlling already printed text to console.
Select or Download Code
Re^2: Controlling already printed text to console.
by humble (Acolyte) on Aug 03, 2012 at 19:01 UTC
    Thank You, frozenwithjoy, VERY MUCH! - For the example and its explanation!

    I've got the point and now will work it out for my case - I have to change the printed string, namely one single char. at its start - like a textual icon for visualisation of a status.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984954]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-12-20 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls