Sorry, forgot to mention that \r does not work, or I use it incorrectly. Example:
foreach $n (1..10) {
print "\r";
print "$n";
sleep 1;
}
When run nothing happens for 9 seconds and then 10 is printed, but nothing else.
| [reply] [d/l] |
When run nothing happens for 9 seconds and then 10 is printed, but nothing else
You need to turn off output buffering; in its simplest form,
adding
$|=1
should do the trick.
Dave.
| [reply] [d/l] |
"10 is printed but nothing else" should have given you the clue that "\r", was, in fact, doing *something* to the other characters. Beyond that, it depends on the console, some consoles delete the entire line and some just return the cursor to the front of the line, so you might need to pad your output with spaces if line you print currently is smaller then the line you printed before.
| [reply] |
#!perl -w
$| = 1;
use strict;
use Time::HiRes qw( sleep );
for ( 1 .. 100 ) {
print "\r \r${_}% Complete.";
sleep( 0.33 );
}
| [reply] [d/l] |
I saw a wonderful example of Win32::Console sometime in the last year that was a demo application that featured drop down menus, background colors, etc.. I *thought* it was a demo bundled up with either the module or one of the common perl distributions/versions. Alas I can't find it anywhere though..and that sucks because I thought it was a gem as far as demo apps go.
In short though if you want a lot of power/ability Win32::Console is an option. If I find the demo app I'll post a link or info of where to find it.
| [reply] |
| [reply] |
Yes! Thats where I saw it.. While puting together a perl 5.8 compile/installation on a windows box a while ago. Its the test script for the Win32::Console module itself. That explains why I couldn't find it on my system. It doesn't install with the module itself - its only included in archive for testing the build.(thanks!)
| [reply] |