Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: PERL Countdown Timer

by Anonymous Monk
on Feb 13, 2013 at 17:53 UTC ( #1018590=note: print w/ replies, xml ) Need Help??


in reply to Re: PERL Countdown Timer
in thread PERL Countdown Timer

I put it in a simple sub. Easy to adjust if you want to include additional parameters such as a pre or post message.

countdown(10); sub countdown($) { #countdown(seconds); my ($duration) = @_; my $end_time = time + $duration; my $time = time; while ($time < $end_time) { $time = time; printf("\r%02d:%02d:%02d", ($end_time - $time) / (60*60), ($en +d_time - $time) / (60) % 60,($end_time - $time) % 60); #00:00:10 $|++; sleep 1; } }

countdown(10, "before", "after"); sub countdown($$$) { #countdown(seconds, "premessage", "postmessage"); my ($duration, $premessage, $postmessage) = @_; my $end_time = time + $duration; my $time = time; while ($time < $end_time) { $time = time; printf("\r%s %02d:%02d:%02d %s", $premessage, ($end_time - $ti +me) / (60*60), ($end_time - $time) / (60) % 60,($end_time - $time) % +60, $postmessage); #before 00:00:10 after $|++; sleep 1; } }


Comment on Re^2: PERL Countdown Timer
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-07-31 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls