palkia has asked for the wisdom of the Perl Monks concerning the following question:

hi
Got a real block on that one.
I managed that so far with files I'm the only one editing,
by keeping a log of that attribute, but that's very limited as you can imagine.

How can I (really) check when a file was last modified ?
Is there a simple direct way, or do I need some modules (which) to do that ?
Is that considered meta-data ?

Thank you very much for any assistance.

Update:
Thank you both very much :-] (Question: Resolved)
I will try all suggested methods eventually,
but for now I liked the simplicity of -M more than all.
I've implemented it as
$initTimeInSec - ((-M $filePath) * 24 * 60 * 60))
it works gr8, with a possible error of up to 1 second (good enough for me ^^).

Thx again

Replies are listed 'Best First'.
Re: How can I tell when a file was last modified
by davido (Cardinal) on Sep 10, 2011 at 04:18 UTC

    This is covered in perlfaq5 under the topic: How do I get a file's timestamp in Perl? There's enough text there that it's probably preferable for you to visit that link rather than have someone paste the contents here.

    See also the -M file test operator, and the File::stat module (both are discussed in the perlfaq referenced above). File::stat is part of the Perl core, so shouldn't be considered an external dependency.


    Dave

Re: How can I tell when a file was last modified
by johngg (Canon) on Sep 10, 2011 at 12:27 UTC

    A quick demo using stat:-

    knoppix@Microknoppix:~$ ls -l xxx -rw-r--r-- 1 knoppix knoppix 11 Jul 30 00:01 xxx knoppix@Microknoppix:~$ perl -MPOSIX=strftime -E ' > say strftime q{%c}, localtime( ( stat q{xxx} )[ 9 ] );' Sat 30 Jul 2011 00:01:18 UTC knoppix@Microknoppix:~$

    I hope this is helpful.

    Cheers,

    JohnGG