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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/