You may want to consider changing the following. It's shorter, and it's probably how I would have written the loop. I realize life is not one big Perl-golf challenge, but in this case I prefer the shorter version.
while ($time > 0) { print " " . ' ' x (3 - length($time)) . "$time $line"; foreach (1..$backcount){print "\b"} $time -= 1; sleep 1; }
to
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; }
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.

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


In reply to Re: Time until event by blokhead
in thread Time until event by halxd2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.