Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Checking file Mod date

by sifukurt (Hermit)
on Jul 19, 2001 at 18:27 UTC ( #98079=note: print w/replies, xml ) Need Help??


in reply to Checking file Mod date

Not to complicate matters, but you could also use stat(). Using stat() is particularly useful if you want to see the actual datestamp that the file was last modified, whereas -M only returns the number of days since modification. It is possible to get get the actual datestamp if you've only used -M, but you'd have to use Date::Manip. To do the whole process using stat(), you could do it something like this:
$sevenDays = 60 * 60 * 24 * 7; $now = time(); foreach $file ( @files ) { $mod_time = ( stat($file) )[9]; if ( $now - $sevenDays < $mod_time ) { # Our file has been modified w/i last 7 days } else { # Hasn't been modified w/i last 7 days } }

It is then a trivial matter to retrieve the exact date of the modification, like so:
$date = localtime( (stat($file) )[9] );
Or, using the first example, since we've already got the modification time stored in $mod_time, we'd simply have to use $date = localtime( $mod_time ).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://98079]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2023-09-27 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?