Waking Up with Perl

While being in the Alps skiing (Argentiere), my cellphone broke due to a 55kg-weight dropping on it. Since I used to set my cellphone’s alarm clock to make me wake up, I had to come up with a better solution. I wrote this perl script:

use strict;
 
my ( $t, $f );
if ( @ARGV == 1 ) {
        $t = $ARGV[0];
        $f = '~/wakeup.mp3';
} elsif ( @ARGV == 2 ) {
        ( $t, $f ) = @ARGV;
} else {
        die 'args: sec, file';
}
 
while ( $t > 0 ) {
        sleep 1;
        $t--;
        my $h = int( $t / 3600 );
        my $m = int( $t / 60 - $h * 60 )  ;
        my $s = int( $t - $h * 3600 - $m * 60 )  ;
        print "$h:$m:$s\n";
}
 
print "BEEP BEEP BEEP\n";
`mplayer $f`;

The script counts down $t seconds. When it reaches zero, $f will start playing. Eight hours equal 28800 seconds.

Unfortunately, writing this script kept me from sleeping anyway.

Maybe Related?

6 Comments »

  1. Why do that much work when a bash oneliner would suffice:
    read t && sleep $t && mplayer wakeup.mp3

    Comment by tobbez — February 26, 2008 @ 6:21 pm

  2. Tim, I really really need some help exploiting an online game. It is PHP. Ive been trying SO hard for a few weeks, but Im such a noob.

    I am willing to pay if you are able to accomplish what Im trying to do. :)

    Im not sure if you can see the email address I listed, but if you can, please email me. If not, post back here and I will leave my email.

    Comment by Jingles — February 26, 2008 @ 7:40 pm

  3. Hej Tim,

    you really need a contact form on your website :) Please contact me if you are interested in developing a Wordpress plugin for me which will of course be monetized properly.

    waiting for your reply, thanks
    Martin

    Comment by Martin — March 15, 2008 @ 4:14 pm

  4. uh.

    perl -e ’sleep(28800);mplayer(”~/wakeup.mp3″)’

    right? :)

    Comment by alpha — March 23, 2008 @ 2:03 am

  5. Alpha, you’re more of a minimalist than I am :)

    Comment by Tim — June 19, 2008 @ 9:54 am

  6. tobbez: Suppose I should learn bash some day.

    Comment by Tim — June 19, 2008 @ 10:07 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

FireStats iconAnvänder FireStats