Perl_Peril has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I've been working with perl for a few weeks now and I need to process a very large data file (about 10 mins of calculations). I would like to display a progress number (perhaps lines processed, etc) to the screen, preferably overwriting the old number (so not to fill up the screen). Does anyone now how to move the cursor back to a specific location while operating under MS-DOS. Please keep in mind that I am running under XP so I only have limited access to external modules. Thanks.

Replies are listed 'Best First'.
Re: Moving the output cursor in Windows
by ktross (Deacon) on May 27, 2005 at 14:37 UTC
    If you print "\r", it returns you to the beginning of the current line. This snippet counts to 10.
    for(1..10){ print "\r", 'line: ', $_; sleep(1); }


    Spem Successus Alit
      OP may not know how to flush the buffer immediately to see the count...
      $|=1; for(1..10){ print "\r", 'line: ', $_; sleep(1); }

      You need to unbuffer STDOUT first for that to work correctly. With buffered output, it just waits for 10 seconds then prints "Line 10".

Re: Moving the output cursor in Windows
by marto (Cardinal) on May 27, 2005 at 14:39 UTC
    Hi,

    This node looks like a cool progress bar. Take a look at it and see if you can adapt it to suit your needs.

    Hope this helps.

    Cheers

    Martin
Re: Moving the output cursor in Windows
by reasonablekeith (Deacon) on May 27, 2005 at 14:38 UTC
    Just use...
    print "\r 10% complete (or whatever)";
    Which will return to the left of the screen before printing. As long as you don't print past the screen width you'll be okay. You can get the screen width using
    use Term::ReadKey; my ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize();
    which would allow you resize the progress bar on the fly.
    ---
    my name's not Keith, and I'm not reasonable.
Re: Moving the output cursor in Windows
by holli (Abbot) on May 27, 2005 at 14:41 UTC
      Thanks for the info. I now have it working. The problem with XP is that ppm only has a limitind number of modules, and I don't have a c-complier (I'm working in a very restrictive research environment)