Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Quickie Alarm Clock

by newrisedesigns (Curate)
on Sep 10, 2002 at 03:04 UTC ( [id://196513]=CUFP: print w/replies, xml ) Need Help??

My alarm clock ran out of batteries just now, so I wrote this to get me up at 7 tomorrow morning.

use Win32::Sound; until((localtime)[2] == $ARGV[1]){ sleep(1); } Win32 +::Sound::Play($ARGV[0]) foreach(0..4);

Just specify a file to play, and the hour when you want to get up.

Yup, no minutes. What did you expect, a custom wake up call? :)

John J Reiser
newrisedesigns.com

Replies are listed 'Best First'.
Re: Quickie Alarm Clock
by Juerd (Abbot) on Sep 10, 2002 at 23:09 UTC

    I often use

    perl -le'sleep 1 until localtime =~ / 07:/; sleep 1, print "\a" while +1;'

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Such flagrant prodigality and needless verbosity is begging for optimisation. 8^)

      (localtime)[2] == 7 and print "\a" while sleep 1

      (ps. the output from localtime doesn't have any ':'s? (in my version anyway))


      Well It's better than the Abottoire, but Yorkshire!
        (ps. the output from localtime doesn't have any ':'s? (in my version anyway))
        Really? In list context, (my version is AS 5.6.1 build 633) I get:

        perl -e "print localtime" 3481710810222521

        In scalar context, however, I get:

        perl -e "print scalar localtime" Tue Sep 10 17:48:09 2002 ^ ^

        I'm guessing that you are in the UK (aren't I a bright boy ;) - my locale (US) won't make a difference here

        (localtime)[2] == 7 and print "\a" while sleep 1

        Did you have to look up the localtime index? I saved some time by not doing that. Besides, your version only beeps for an hour ;)

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

Re: Quickie Alarm Clock
by dantie (Initiate) on Sep 18, 2002 at 15:14 UTC
    Minutes? Seconds? Why not just do

    perl -e 'use Time::Local;sleep(timelocal((0,45,8,19,8,102))-time);prin +t "\a" while sleep 1'

    This will at least save some CPU time while still doing something you should better do with crond, atd, or smth. similar on Win32 Plattforms.

    lg,
    daniel

Re: Quickie Alarm Clock
by Anonymous Monk on Sep 10, 2002 at 14:05 UTC
    This is not a oneliner, so why all the onelinedness?
    It's distracting.
    perl -MWin32::Sound -e sleep(1)until((localtime)[2]eq$ARGV[0]);Win32:: +Sound::Play($ARGV[1])for1..10; 7 Wakeup.wav
Re: Quickie Alarm Clock
by Anonymous Monk on Sep 25, 2002 at 10:46 UTC
    This is assuming your Windows machine actually stays running until you want to get up :-)
Re: Quickie Alarm Clock
by Anonymous Monk on Sep 17, 2002 at 16:07 UTC
    if you have linux or sun machine u can use cron job. ( I am using this) or in windows you can use scheduled tasks. :)
Re: Quickie Alarm Clock
by /dev/trash (Curate) on Sep 13, 2002 at 03:06 UTC
    It didn't work for me. I'm using Active State Perl and I made sure teh wav file existed but at 11, nothing happened. No errors nothing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://196513]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-04-19 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found