Do you know where your variables are? | |
PerlMonks |
Real Time Progress Bar in consoleby westrock2000 (Beadle) |
on Oct 09, 2010 at 06:56 UTC ( [id://864328]=perlquestion: print w/replies, xml ) | Need Help?? |
westrock2000 has asked for the wisdom of the Perl Monks concerning the following question:
I am analyzing a log file line by line. It may have anywhere from 2K to 1 million lines that have to be anaylzed. So it can take a while and I wanted to give a way to let the user know it wasn't locked up.
My method to anaylize the file was to read it too an array and then check each line of the array using a foreach loop. All that stuff works fine. But when I tried to insert a progress bar, I got an unexpected result and after some testing I am starting to come to the conclussion that Perl doesn't write to the screen like I thought it did. What I came up with was simply find 10% of the array's size and everytime I come to that number write a character to let the user know we have incrememnted another 10% into the array.
So this should write 00 to the screen each time I get 1/10th of the way through the array and I should end up with 20 "0" in a row. And it works. The issue is that the for loop runs it course AND THEN displays the 20 0's lined up. So then I tried this to test the behavior.
And I again got the exact same behavior. So this led me to believe that Perl does not print to the console in real time. I am guessing that it interprets what needs to be printed to the screen and then once it reaches a stopping point it then dumps to the screen. So the "sleep 1" doesn't work because it just pauses the script. Where as doing a chomp($input=<>) would display properly, but at the expense of being of no practical use. So going by this logic, is there a way to tell Perl to go ahead and print to the screen, but then keep right on going through the script?
Back to
Seekers of Perl Wisdom
|
|