mtime as returned by (stat($filename))[9] is seconds since the epoch on your particular platform.
To see when the beginning of your machine's epoch was:
print scalar gmtime(0);
Some modules useful for working with date/time:
| [reply] [d/l] [select] |
Bollocks! I messed up CPAN links here are the corrected links:
Date::Format
Date::Calc
Date::Manip
Thank the gods! I had time on my side.
<a href="http://www.georgian.net/~mitd>MitD -- Made in the Dark
'My favourite colour appears to be grey.'
| [reply] |
mtime is the number of seconds since 1970 (at least on UNIX-ish systems).
You can compare it to time() to see how old the file is.
my $mtime = (stat $filename)[9];
my $age = time() - $mtime;
die "HEY! $filename was created in the future!\n"
if $age < 0;
print "$filename is $age seconds old\n";
| [reply] [d/l] [select] |
| [reply] |
If you don't need the other stuff that comes from stat(), you may want to consider using the -M file test operator, which yields the age (since 'last modified') for the file, in (fractional) days. | [reply] |
Actually, it's the last modified for a file, from the moment the script started. If your script has been running for 48 hours (it could happen), then -M is totally off course. stat is in this case a much safer approach.
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur.
| [reply] |
Well, actually the filetest operators compute their deltas against the value of $^T, which is initialized during startup. However, you may reset it if you think it's value might be getting stale:
$^T = time();
$age = -M $file;
-Blake
| [reply] [d/l] |
if you want to know everything about the time, use the localtime function:
my $mtime = (stat $filename)[9];
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($m
+time);
All list elements are numeric, and come straight out of a struct tm. ... In particular this means that #mon has the range 0..11, $wday has the range 0..6, and the year has had 1,900 subtracted from it. (You can remember which ones are 0-based because those are the ones you're always using as subscripts into 0-based arrays containing the month and day names.)
| [reply] [d/l] |