Solved

get the time when the file is modified in perl

Posted on 2006-06-14
5
409 Views
Last Modified: 2010-04-17
Hi all,

How to get the time at which the file has be last modified in perl?
Thank you.
0
Comment
Question by:bladefish
5 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 63 total points
ID: 16904818
Quote: http://omaha.pm.org/emails/2003/msg00176.html     [Fwd: Daily Perl FAQ - How do I get a file's timestamp in perl?]
Question: How do I get a file's timestamp in perl?

    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:

        $write_secs = (stat($file))[9];
        printf "file %s updated at %s\n", $file,
            scalar localtime($write_secs);

    If you prefer something more legible, use the File::stat module
    (part of the standard distribution in version 5.004 and later):

        use File::stat;
        use Time::localtime;
        $date_string = ctime(stat($file)->mtime);
        print "file $file updated at $date_string\n";

    Error checking is left as an exercise for the reader.
<--
0
 
LVL 10

Assisted Solution

by:jagadeesh_motamarri
jagadeesh_motamarri earned 62 total points
ID: 16905142
Hi bladefish,

Well here some more variations of what you are looking for -

How to add the last date modified using Perl CGI - http://www.tdscripts.com/lastmodified.html

How can I put a Last modified date on my page using PERL - http://www.htmlforums.com/archive/index.php/t-2862.html

_____Jags.
0
 
LVL 4

Expert Comment

by:v_karthik
ID: 16908699
http://open.itworld.com/5040/nls_unix_fileattributes_060309/page_1.html

Gets you literally everything about the file.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question