home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!destroyer!gatech!concert!rock!cole
- From: cole@concert.net (Derrick C. Cole)
- Subject: help with timelocal.pl
- Message-ID: <1992Aug14.190949.10466@rock.concert.net>
- Sender: news@rock.concert.net
- Organization: MCNC Data Operations
- Date: Fri, 14 Aug 1992 19:09:49 GMT
- Lines: 39
-
- Greetings, again!
-
- Does anyone have a good subroutine for computing the difference in seconds
- between two time stamps? I'm trying to use timelocal() in mine, but it never
- returns:
-
- require "/usr/local/lib/perl/timelocal.pl";
- chop($year = `date +\"\%y\"`);
-
- %months = ('Jan', 0, 'Feb', 1, ...);
-
- sub timediff {
- local($now, $then) = @_; # $now and $then of the form "Mon Day H:M:S"
-
- ($nM, $nD, $nh, $nm, $ns) = $now =~ /^(\w+) (\d+) (\d+):(\d+):(.*)/;
- ($tM, $tD, $th, $tm, $ts) = $then =~ /^(\w+) (\d+) (\d+):(\d+):(.*)/;
-
- $tsec = timelocal($ts, $tm, $th, $tD, $months{$tM}, $year);
-
- if ($months{$nM} < $months{$tM}) {
- $year++;
- }
-
- $nsec = timelocal($ns, $nm, $nh, $nD, $months{$nM}, $year);
-
- $diff = $nsec - $tsec;
- }
-
- I'm doing something wrong, but can't figure out what it is (don't use packages
- very often, if that's it...) Can anyone improve upon/fix this subroutine?
-
- Any and all help greatly appreciated!
- Derrick Cole
-
- --
- "If all the salmon caught in Canada in one year were laid end to end across the
- Sahara Desert, the smell would be absolutely awful."
- -- unknown
- ======
-