J
James E Keenan
Let's say that I wish to process every file in a given directory that was
last modified more than 14 days ago. From various parts of the Camel book,
it appears I could test the age of the file in 1 of 2 ways.
### approach using 'stat' ### Camel pp 800-801
my ($file, $days_ago, $DAY, $earlier);
$DAY = 60 * 60 * 24;
$days_ago = 14;
$earlier = time() - ($days_ago * $DAY);
....
if ( (stat($file))[9] < $earlier ) {
# process $file
}
### approach using file test operator '-M' ### Camel pp 98-100
if (-M $file > 14) {
# process $file
}
### [end code samples] ###
For the purpose of argument, let's assume that the "at the point the Perl
script started running" proviso for the file test operator is not meaningful
from the current time. Given that assumption, is there any particular
reason to prefer the more verbose approach using 'stat' to the simple one
using the '-M'?
jimk
last modified more than 14 days ago. From various parts of the Camel book,
it appears I could test the age of the file in 1 of 2 ways.
### approach using 'stat' ### Camel pp 800-801
my ($file, $days_ago, $DAY, $earlier);
$DAY = 60 * 60 * 24;
$days_ago = 14;
$earlier = time() - ($days_ago * $DAY);
....
if ( (stat($file))[9] < $earlier ) {
# process $file
}
### approach using file test operator '-M' ### Camel pp 98-100
if (-M $file > 14) {
# process $file
}
### [end code samples] ###
For the purpose of argument, let's assume that the "at the point the Perl
script started running" proviso for the file test operator is not meaningful
from the current time. Given that assumption, is there any particular
reason to prefer the more verbose approach using 'stat' to the simple one
using the '-M'?
jimk