On 2004-11-22 Dan Buettner wrote:
>Ideally, I'd like to have the window have a fixed display (no
>scrolling) and always output the information from a specific thread in
>a specific position.  In other words, Thread 1 gets the first 2 lines,
>Thread 2 gets lines 3 and 4, etc.

Maybe you could extrapolate from this, a simplified version of a
subroutine in my own local ::Utils module. The subroutine make_counter()
takes two arguments, a fixed initial part, here called $label, and a
starting number. It returns a closure that you use inside your loop. 

Note the $|++, which assures immediate output (to the terminal screen).

For your use, what you especially want to get from this example is the
use of the Perl character "\b", which outside of regular expressions
means "backspace". The point is to print "\b" the same number of times
as the number of characters you want to back up before printing the
updated output. I believe you should be able to stack fixed and varying
lines with a little practice...

#!/usr/bin/perl

# trivial_count.pl
 
use strict;
use warnings;

$|++;

my $max     = $ARGV[0] || 10000;

print "Searching...\n";

my $counter = make_counter("Here's how many I've found: "); 

for (1..$max) {
    print $counter->() 
}

print "\n";

sub make_counter {
    my ($label,$start)  = @_;
    $label              ||= 'Count:';
    my $count           = $start ||= 1;
    my $flag            = 1;
    return sub {
        $flag ? 
           $flag-- && "$label  " . $count :
               "\b" x length($count) . ++$count;
    }
}
__END__


bva$ perl /Volumes/Programming/trivial_count.pl 678
Searching...
Here's how many I've found:   678
bva$ 



HTH

- Bruce

__bruce__van_allen__santa_cruz__ca__

Reply via email to