Solved

get the time when the file is modified in perl

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …
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 …

707 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

18 Experts available now in Live!

Get 1:1 Help Now