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

How do I get a file's timestamp in perl?

by faq_monk (Initiate)
on Oct 13, 1999 at 03:42 UTC ( #808=perlfaq nodetype: print w/ replies, xml ) Need Help??

Current Perl documentation can be found at


If you want to retrieve the time at which the file was last read, written, or had its meta-data (owner, etc) changed, you use the -M, -A, or -C filetest operations as documented in the perlfunc manpage. These retrieve the age of the file (measured against the start-time of your program) in days as a floating point number. To retrieve the ``raw'' time in seconds since the epoch, you would call the stat function, then use localtime(), gmtime(), or POSIX::strftime() to convert this into human-readable form.

Here's an example:

        scalar localtime($write_secs);


    use File::stat;
    use Time::localtime;

Error checking is left as an exercise for the reader.

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
As of 2014-03-16 09:00 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (326 votes), past polls