On Tue, 2009-01-06 at 06:23 -0800, h3xx wrote:
> I find it's easier (and in this case totally doable) if you make
> something like this:
> 
> for my $count (10 .. 0) {
>   printf STDERR "%2d seconds remaining...\n", $count;
>   sleep 1;
>   print STDERR "\e[A";
> }
> 
> ^ "\e[A" is the VT-100 code to move the cursor up one line.
> 
> ^ Also, expanding the number of seconds to two characters wide ensures
> we're not going to be seeing trailing characters that wouldn't get
> over-written when the next line is printed.
> 
> ^ Also, a tip exists here: STDERR is unbuffered so you get all your
> output immediately.
> 
> If that doesn't work you could always use Curses to move the cursor
> back and forth...
> 
> Don't know if Windows will support that, though.
> 

Most xterms respond to the ANSI escape codes
http://en.wikipedia.org/wiki/ANSI_escape_code


#!/usr/bin/perl

use strict;
use warnings;

{
  local( $| ) = 1;
  print "The quick brown fox jumped over the lazy dogs.";
  print  "\e[1G";

  my $i = 20;
  while( $i >= 0 ){
    sleep 1;
    print "\e[1K\e[1G";
    print "$i seconds";
  }continue{
    $i --;
  }
  print "\n";
}


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication as it is about 
coding.

"It would appear that we have reached the limits of what it is possible to 
achieve with computer technology, although one should be careful with such 
statements, as they tend to sound pretty silly in 5 years."
  --John von Neumann, circa 1950



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to