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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print not printing every time.. 1

Status
Not open for further replies.

inspleak

Technical User
Mar 10, 2004
14
US
Hey guys, quick question..

I'm trying to make a little progress indicator like [23/1000] or something like that.

What I figured I could do is go through the loop and at the end of the loop:

print "\r [$myPart/$myTotal]";

However it only seems to print the very last one.
So I tried:

print "[$myPart/$myTotal]\n";

that works, however it prints the updated line on the next line of course.. soooo... is there a way to force print to update the line without going to the next line?

Thanks very much as always!
 
It seems as though this may have something to do with the fact that I have open files and I am printing to them at other points in the code...

I could be totally wrong, but figured I should mention it..

thanks!
 
Ahh ha!

This fixed it:

#save old file handle and set STDOUT as default
my $oldFileHandle = select STDOUT;

#I think this forces a flush of the selected output
$| = 1;

#restore old file handle
select $oldFileHandle;

Thanks!
 
$OUTPUT_AUTOFLUSH is the same as $|, it basically means your flushing the buffer

HTH
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top