So my wife and I are expecting our first baby. Today in fact, although it looks as though she will be a bit late.

I got tired of trying to figure out which button did what on the little digital watch we were trying to use to time contractions, so I threw this together. There is obviously room for improvement (or even golfing), but something tells me that I should be doing something else right about now...

#!/usr/bin/perl -w use strict; use warnings; my $last = time; while( <> ) { my $time = time; my $interval = $time - $last; print localtime($time)." ($interval)"; $last = $time; }

We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re: Giving birth with perl
by rhesa (Vicar) on Jul 28, 2006 at 01:47 UTC
    You too eh? We're expecting our first somewhere next week :)

    PS. I'd divide the interval by 60...

Re: Giving birth with perl
by bart (Canon) on Jul 28, 2006 at 13:38 UTC
    You could use Time::HiRes, so you can get a finer than 1 second precision for the interval! (up to 55ms, on Windows, the clock is updated 18 times per second)

      I could, but my wife doesn't have resolution that high. It takes her a second or two to tell me it's started or stopped anyway. :)


      We're not surrounded, we're in a target-rich environment!
      I thought that got fixed? Changes supports my memory:
      1.53 [2003-12-30] - Windows: higher resolution time() by using the Windows performance counter API, from Jan Dubois and Anton Shcherbinin. The exact new higher resolution depends on the hardware, but it should be quite a bit better than using the basic Windows timers.

      Here's some code that will test this. I only have version 1.2, so I'm still using the lower res timer.

      use Time::HiRes qw( time sleep ); my @times = map { time } 0..200; #my @times = map { sleep(0.001); time } 0..200; my @time_diffs = map { $times[$_] - $times[$_-1] } 1..$#times; $, = "\n"; $\ = "\n"; print @time_diffs;
Re: Giving birth with perl
by Zero_Flop (Pilgrim) on Aug 06, 2006 at 15:38 UTC
    My brother did the same type of thing years ago. He sold computers and he did it on the first Macintosh. He had it also print out a chart of the contractions. This was about 21 yrs ago since I think his son is that old now. (maybe 20, never get that right)

    Anyway, he said the doctor just looked at him funny when he showed up with graph in hand. He even made the news paper at the time which I think was pushed in part by apple. It was good advertising for the Personal in PC and he had written the program in their latest and greatest programming language.
      I was born about 45 years too late. I woulda been in the town paper.

      _________________________________________________________________________________

      I like computer programming because it's like Legos for the mind.

Re: Giving birth with perl
by Anonymous Monk on Jul 31, 2006 at 22:33 UTC
    Wait a minute, your wife is giving birth and your writing Perl scripts.. shouldn't you be more focused on tending to her needs and breathing.. ;)