in reply to Time until event
towhile ($time > 0) { print " " . ' ' x (3 - length($time)) . "$time $line"; foreach (1..$backcount){print "\b"} $time -= 1; sleep 1; }
No need to do the formatting of the time yourself, sprintf or printf can do it for you. The %3s part means format the string $time, right-justified within a column of 3 characters (space-padded if necessary). You could also do %3d as part of your printf format to do the same thing with zero-padding instead. See the perldoc page for printf for more fun options.while ($time--) { printf(" %3s %s", $time, $line); print "\b" for (1..$backcount); # or this could even be written as: # print "\b" x $backcount; sleep 1; }
Having said that, I haven't actually executed your code, but I wonder if printing out backspaces isn't the most efficient way to erase the line. I don't have any other suggestions though, so I may be off base. Anyway, good job in saving/replacing $| within your sub. Returning globals to their previous values can save a lot of headaches.
blokhead
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Time until event
by petral (Curate) on Sep 19, 2002 at 21:56 UTC |