Jürgen Exner said:
I was about to suggest the same when i double checked the documentation:
-M Age of file in days when script started.
-A Same for access time.
-C Same for inode change time.
This is a confusing file test. There is some documentation that says
that -M is the age, others say that it is the modification date.
However, from what I noticed, there is more documentation that says it
is the modification date.
A Google search will reveal sites that agree that is is the
modification date, and others that say that it is the age.
I decided to write a test script (I assigned $0 to $file to make the
test file become the perl file itself):
#!/usr/bin/perl -w
use strict;
# Helper subroutine to format time:
sub formatTime ($);
# The file for the modification test:
my $file = $0;
# The number of seconds since the file was modified from the
# -M file test:
my $mSeconds = -M $file;
# Convert from fraction of day to seconds.
# 86400 is the number of seconds in a day.
$mSeconds *= 86400;
# Get the time the file was modified.
# $seconds is the number of seconds from when the file was
# modified to when the script started.
my $mTime = $^T - $mSeconds;
print "Stat: Last Modified for $file: ", formatTime((stat($file))[9]),
"\n";
print " -M: Last Modified for $file: ", getTime $mTime, "\n";
# Helper subroutine to format time:
sub formatTime ($) {
my($second, $minute, $hour, $monthDay, $month, $year, $weekDay,
$yearDay, $isDST) = localtime $_[0];
$year += 1900;
$month += 1;
my $ampm;
if($hour > 12) {
$hour -= 12;
$ampm = 'P.M.';
} else {
if($hour != 12) { # Noon is P.M.
$ampm = 'A.M.';
} else {
if($hour == 0) { # Midnight is A.M.
$hour = 12;
$ampm = 'A.M.';
} else {
$ampm = 'P.M.';
}
}
}
return sprintf("%02d/%02d/%02d %02d:%02d:%02d $ampm", $month,
$monthDay, $year, $hour, $minute, $second);
}
Results:
Stat: Last Modified for Modified.pl: 10/26/2005 12:11:39 P.M.
-M: Last Modified for Modified.pl: 10/26/2005 12:11:39 P.M.
The test makes me think that the -M test returns the modification date.
David