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. On Jan 4, 9:36 pm, shawnhco...@magma.ca (Mr. Shawn H. Corey) wrote: > On Sun, 2009-01-04 at 19:33 -0700, bft wrote: > > Hello all, > > I am on a windows box and I am trying to have a count down timer print > > out the seconds remaining without new lining it. i.e. I do not want a > > screen that looks like this... > > > 19 seconds remaining > > 18 seconds remaining > > 17 ... > > > I would like it to print all on the same line. And I cannot clear the > > screen after every second because there is other information on there I > > would like to keep. > > > A google search has only netted me "perl one liners" > > > I have also tried \r (carriage return) hoping it wouldn't give me the > > new line, but it did not. I did see where activeState perl has trouble > > with some escape sequences though. > > > Any help would be appreciated. > > You can use the backspace character. See `perldoc perlop` and search > for m/\\b/ > > #!/usr/bin/perl > > use strict; > use warnings; > > my $Backup_Count = 0; > > sub back_and_print { > my $text = shift @_; # no tabs, no newlines! > > print "\b" x $Backup_Count; > print " " x $Backup_Count; > print "\b" x $Backup_Count; > $Backup_Count = length $text; > print $text; > > } > > $| = 1; # flush STDOUT after every print > for my $i ( 0 .. 10 ){ > my $sec = 10 - $i; > back_and_print( "$sec seconds" ); > sleep 1;} > > back_and_print( "" ); > print "\n"; > > -- > Just my 0.00000002 million dollars worth, > Shawn > > Programming is as much about organization and communication as it is about > coding. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/