Hello,
I've developed a perl script that runs over tons of X and does Y.
Anyhow, while in a loop, I try to print a progress, it works as long as I use "\n" in the print, but when I remove the "\n" it will only print the line at the end of it.
Expected result would be that it would print:
Progress: 1 2 3 4 5 6 7 8 ..(these numbers will come up while the loop runs)
and instead I get:
Progress: 1 2 3 4 5 6 7 8 9 10 11 12 13 - 100 In 1 print (and after a long time).
When using print "$x\n" (where $x is the progress %) it works perfectly, but ugly.
Any ideas?
Thanks!!
print " progress: \n"; foreach my $query (@queries) { $count2++; my $xx = ($count2/$count)*100; $xx = sprintf "%.0f", $xx; if ($xx % 10 == 0) { if ($xx != $laststatus) { print " * $xx\n"; # removing the \n here will stop printing:( $laststatus=$xx; } } }
In reply to Print does not work in loop unless used with \n by Mistdemon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |