Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unget previous chars from print function from the standard output 2

Status
Not open for further replies.

CristianLuca

Programmer
Oct 25, 2007
36
RO
So i'm trying to make a simple print, then to unget all the x last chars or last output from the standard window and i do not know how.Eny suggestions will be appreciated.

# example :

print "Hello world"; # output : Hello world
# print unget(5); or a method similiar this is just a suggestion
print "Sam" # output : Hello Sam

# i'm just interested to print in the standard output window
# not in a file.

Thanks you,
CL

 
You going to have to give me some more info as I have no idea what "unget" is

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
print unget(5); it's just a suggestion for what i had in mind for this functionality, from what i know this function does not exist, what i'm interested about is a method for undoing some previous output, or a part from the previous out.

The reason for why i need this is that i want to output something like this :

output window :
_________________________________________________
* Process begins |
progress : 1% |
|
_________________________________________________

output window after a while :
_________________________________________________
* Process begins |
progress : 2% |
|
_________________________________________________

 
Use the carriage return character "\r". This will bring the cursor back to the beginning of the line and you can instead print "Hello Sam".

Code:
[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple]Hello world[/purple][red]"[/red][red];[/red] [gray][i]# output : Hello world[/i][/gray]
[black][b]print[/b][/black] [red]"[/red][purple][purple][b]\r[/b][/purple]Hello Sam[/purple][red]"[/red] [gray][i]# output : Hello Sam[/i][/gray]

The only thing to note is that the output will actually read "Hello Samld". To fix that you simply add two extra spaces to your second print statement to cover up the ld from world.

- Miller
 
I know there is a "status bar" module.. but you can also look at the ANSI module (Term::ANSIColor I think)..
Even if you don't want the color part of it it will do positioning (there might be an easier way but I have used this one before)..

you can say
print 1,1 "This is a test";
then you can say
print 1,1 "No more test anymore"
and the second print will over write the first print because they are both at the same location.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Hey guys, the backspace character should do that:
Code:
print"Hello world";
print"\x8 \x8"x5;
print"Sam";
If the output window erases the charcters already there by backspacing (a DOS window doesn't), simply use [tt]print"\x8"x5;[/tt]

Franco
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Hmm, all of them cancel my previous print. I don't know how perl works in the "back" but if i do something like this :

print "Hello World";
# some actions that takes a several seconds
print "\rSam";

it will print just the "Hello Sam" instead of :
"Hello world" then after those actions passed "Hello Sam". So Hello world is never printed.
 
correction :

print "Hello World";
# some actions that takes a several seconds
print "Hello \rSam"; #correction
 
The output of print is line buffered and, if there is no line terminator "\n", you could wait indefinetely (or till program ends) to see your output. Put [tt]$|=1;[/tt] before the first print, it unbuffers STDOUT.

Franco
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top