I just slapped together this timer program, and I thought I'd share it. It could be useful for all sorts of lovely things like cooking eggs just right, playing boggle, or timing naps at work. I use it for timing meditation breaks. I've wrapped in a batch file, people with real operating systems can remove the taint as an exercise.

Updated: Added archen's code suggestion as a comment. And then later added bbfu's code too. Plus links on monk names.

@rem = ' @echo off goto BEGINBAT # ----------------------------------------------- # # Do not run this software, it will make you die. # # ----------------------------------------------- # :BEGINBAT rem search the path if batch is not in current directory set PARGS= if not exist %0.bat set PARGS=-S perl %PARGS% %0.bat %1 set PARGS= goto ENDOFBAT :USAGE echo Print some usage info here. goto ENDOFBAT '; # Perl Script goes here. ++$|; print <<END; ******************* My Stupid eggtimer. ******************* Enter a duration in seconds. Q to quit. END while (1) { my $time = get_time(); print "Sleeping for $time seconds.\n"; foreach (1..$time) { # Comment out this print and uncomment the next print to impl +ement print "."; # archen's most excellent suggestion, # print "\b" x length(localtime), scalar(localtime); # or try bbfu's great idea: # print "\b" x length($time-$_+1), $time-$_; sleep(1); } beep(); } sub beep { my $count = shift || 10; # Ring some ASCII bells print chr(0x07)x$count; } sub get_time { my $time; do { print "\n-> "; $time = <>; chomp $time; print "\n"; exit if $time =~/^q/i; } while ($time ne $time+0); return $time; } __END__ :ENDOFBAT


TGI says moo

Replies are listed 'Best First'.
Re: An Egg(?) Timer
by archen (Pilgrim) on Oct 09, 2001 at 08:16 UTC
    just a little aesthetic thing....

    you print a '.' each second, but if you set the timer for... a long time, the screen fills with dots and you sort of lose track (reminds me of using dos ftp with hashes on and transferring a 10 meg file). Anyway, I'd maybe think about maybe just printing out the time.

    print "\b" x length(localtime), scalar(localtime);

    I'm sort of a nit-picker on that stuff

      Or even the number of seconds remaining (untested):

      print "\b" x length($time-$_+1), $time-$_;

      Also, TGI should probably make sure that autoflush is on (++$|), though s?he doesn't seem to be having a problem with it thus far...

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

Re: An Egg(?) Timer
by strfry() (Monk) on Oct 12, 2001 at 00:54 UTC
    thats pretty slick! much slicker than this patch to get_time() i put in there to stop it from erroring if i typo - as i usually wind up doing (8 there's likely a better way, but it's near 5:00pm EST, and i'm about to clock out.
    sub get_time { my $time; do { print "\n-> "; $time = <>; chomp $time; print "\n"; exit if $time =~/^q/i; no warnings; # quick patch next if $time =~ /([^\d])/; # please fix use warnings; # me (: } while ($time ne $time+0); return $time; }

    dont flame me too bad - i just hated to see the 'exiting subroutine via next ...' warning. it made it ugly. ):

    strfry()