[EMAIL PROTECTED] wrote:
> Gentle Readers,
> 
> I'm trying to eliminate the calculation of Julian Day Numbers from a
> file aging script (yes, still). I hit on the clever idea of using
> directly the mtime and atime figures returned by stat() and comparing
> them with the number returned by time(), which would be "today".
> Clever boy that I am, I noticed that the first five digits of a
> stat() mtime or atime had a one-to-one correspondence with the date
> (e.g., 08/01/02 -> 10288,  08/13/08 -> 10292, 08/15/02 -> 10294,
> etc.), and that two Xtimes that had different times on the same date
> would differ only in the last five digits.        
> 
> Well, the four-watt light bulb turned on, and I came up with the
> following: 
> 
> $today = time;
> @stat_set = stat( $file );
> $atime = $stat_set[8];
> $mtime = $stat_set[9];
> 
> $newest_date = ($atime > $mtime) ? $atime : $mtime;  # get "most
> recent" date 
> 
> $file_age = int( ($today - $newest_date) / 100_000); # leftmost 5
> digits = date portion 
> 
> Problem is, for a given file, I've got a date for atime of 23 Mar,
> 2004 (from localtime($atime)), and today is 07 Oct, 2004, right? JDNs
> tell me that these dates are 198 days apart, right?  
> 
> BUT the numbers I get for my nifty new code are 1097160667 for today
> (from time()) and 1080054365 for the March date (the "actual" return
> value of (stat())[8]). Now running these numbers through localtime()
> gives the right dates for them, and the days between dates for them
> is, you guessed it, 198 days. Unfortunately, the result of the
> above-coded calculation for $file_age ((1097160667 - 1080054365) /
> 100,000) gets me a value of 171 days. That's off by 27 days!      
> 
> So the $64,000 questions are: WHERE did I go wrong, WHAT did I miss?

The flaws in your date calculation logic have already been mentioned,
but getting the file's age in days is not exactly difficult. The
following does pretty much what you seem to be attempting.

sub min {$_[0] < $_[1] ? $_[0] : $_[1]; }
my $file_age = min(-M $file, -A $file);

(See 'perldoc -f -X').

HTH

-- 
Brian Raven
 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
-----------------------------------------------------------------------


_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to