Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Controlling already printed text to console.

by frozenwithjoy (Priest)
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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984954]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-07-25 11:37 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (370 votes). Check out past polls.