Solved

get the time when the file is modified in perl

Posted on 2006-06-14
5
405 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 108
topping2 challenge 13 80
Basic Java Case or If-Else statement... 3 43
Definitions and default visual studio colors 5 58
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now