[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Modification date



>Does anyone know how to get the modification date of
>a file using MacPerl?
>
>TIA,
>gene

Carl Johan Berglund answered this question a few days ago:

---------------------

-M $filename

returns the number of days since the file was last modified, measured from
the time the script started. If you want the time and date when it was
modified, you can subtract it from $^T, which is a special variable
containing the time (in seconds from Jan 1, 1970) when the script started:

$mod_date = $^T - (-M $filename);

If you want to print the date, you can use localtime:

print scalar localtime($mod_date);

localtime can also be called in array context if you want to extract the
day, month, year, etc. from the date:

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mod_date);

If called without an argument, localtime uses the current time... But now
I'm diverging from your question :-)

---------------------

This works fine with one small change. Because $^T is measured in seconds
while -M $filename is measured in days,

$mod_date = $^T - 86400*(-M $filename);

(There are 86400 seconds in a day).


Bill Birkett
Precison Color, Inc.
Plymouth, MI




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch