Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Action Based on File's Last Modification Time: Is One Approach Better?

Reply
Thread Tools

Action Based on File's Last Modification Time: Is One Approach Better?

 
 
James E Keenan
Guest
Posts: n/a
 
      10-14-2003
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


 
Reply With Quote
 
 
 
 
Steve Grazzini
Guest
Posts: n/a
 
      10-14-2003
James E Keenan <(E-Mail Removed)> wrote:
> 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.


[ using stat() and -M ]

> 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.


This is what trips people, though, when they use it in long-running
daemons, mod_perl handlers, etc.

> Given that assumption, is there any particular reason to prefer the
> more verbose approach using 'stat' to the simple one using the '-M'?


No. -M is simpler, easier to read, and probably a bit faster.

--
Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Last "real" modification date of file Bart Van der Donck Perl Misc 3 06-18-2008 06:01 PM
Struts mapping action to action??? runescience Java 3 02-07-2006 04:07 PM
Struts Forward to an Action from an to Action and URLs rjweytens Java 6 06-25-2004 01:49 PM
Get the date of last modification of a file Manuel Bastioni Python 6 09-09-2003 06:07 PM
Struts Static Action Form vs Dyanamic Action Form Joe Bloggs Java 1 08-03-2003 02:30 AM



Advertisments