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

I'm writing an update program that uses rsync to copy code files from one location to the other. First I do a dry-run to get the list of files, then I match them with a regex to see which ones are perl files. Then I check them with `perl -wc $file_to_test`.

What I'd like to do is have a running total that says:

Testing file: XXX
Passed: 30
Failed: 2

This spans multiple lines, and, rather than printing those three lines with \n over and over again, I'd like to have them as a sort of running tally. I know that I can return to the beginning of the last line printed with \r and just overwrite one line, but how do I do this across multiple lines?

Replies are listed 'Best First'.
Re: How to re-print multiple lines?
by oko1 (Deacon) on Jul 09, 2008 at 19:51 UTC

    This may sound silly, but... would clearing the screen work for you?

    $c = qx{/usr/bin/clear}; for my $file (@list){ # Do whatever testing you want here print "${c}Testing file: $file\nPassed: $p\nFailed: $f\n" }

    Another approach, if it's available to you, is to launch an xterm that's only 3 lines high by , e.g., 25 characters wide (or whatever you need to accomodate your text), then print your output in it with a preceding (but without a trailing) newline.

    my $seen; for my $file (@list){ # Do whatever testing you want here print "\n" if $seen++; print "Testing file: $file\nPassed: $p\nFailed: $f" }

    I've used this approach a couple of times, and it works well.

    
    -- 
    Human history becomes more and more a race between education and catastrophe. -- HG Wells
    
Re: How to re-print multiple lines?
by jethro (Monsignor) on Jul 09, 2008 at 19:00 UTC
    Maybe you can live with the following format:

    File: XXX Passed: 30 Failed: 2
    Now you only have the last line to write over.

    Just make sure that you pad the numbers with spaces so that they are always the same length, this will avoid shifting text.

Re: How to re-print multiple lines?
by jds17 (Pilgrim) on Jul 09, 2008 at 18:51 UTC
    The following node contains plenty of alternatives on how to do this: How to UPDATE rather than append to STDOUT?.

    Update:
    hmmm... I was too fast, most proposals cannot handle multiple scrolls...
    But in case you can manage to install Term::Screen on your system, you can easily implement what you want!

Re: How to re-print multiple lines?
by moritz (Cardinal) on Jul 09, 2008 at 19:09 UTC