Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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; } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018590]
[holli]: mmh. maybe a user handle "dry arian" is a bit unfortunate? https://www. dryarian/
[Discipulus]: exists!
[shmem]: holli, agreed. "dry airan" would be slightly better :P
[holli]: virtualsue: How much was left?
[shmem]: Discipulus: oh. tatsächlich.
shmem missed his monkday yesterday :P - 12 years and way to go...
[1nickt]: Happy Monkday shmem. I was at my stepson's birthday party and thought of you.
[virtualsue]: holli about half
[choroba]: "Tatsächlich, das ist die Knochenstruktur eines Bettlers!" ??
shmem bows. Thank you

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2017-11-21 12:52 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (301 votes). Check out past polls.