Archive for February, 2008

You are now browsing the archive for February in 2008.

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.

FireStats iconAnvänder FireStats