Action Based on File's Last Modification Time: Is One Approach Better?
From: James E Keenan (nospam_for_jkeen_at_concentric.net)
Date: 10/14/03
- Next message: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Previous message: Alan J. Flavell: "Re: Named Pipe Permissions Question"
- Next in thread: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Reply: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Oct 2003 01:58:50 GMT
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
- Next message: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Previous message: Alan J. Flavell: "Re: Named Pipe Permissions Question"
- Next in thread: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Reply: Steve Grazzini: "Re: Action Based on File's Last Modification Time: Is One Approach Better?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]