lastmodified

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: Re: Perl question comparing lastModified time to now
From: Cameron Simpson <cs@zip.com.au>
Date: Mon, 6 Mar 2000 11:57:36 +1100


On Sun, Mar 05, 2000 at 01:08:24PM -0500, gnielson wrote:
| I am trying to figure out a way to test a file with perl to find out when
| it was lat modified and if that was within the last minute, do something,
| otherwise exit.
| 
| I've gotten as far as this:
| 
| $file='filename.txt';
| $lastModified = printf "%f", -M $file;
| 
| which gives me a number such as 0.122986 if the file was modified around a
| day ago and 0.000023 if it was modified just a few seconds ago. Is this
| modified number in seconds? How is it calculated? I tried an if/else
| statement where if $lastModified was less than 0.000060 an action would
| happen but I could not get it to work.

Well, you could Read The Fu^hine Manual.

"man perlfunc":
	[...]
	-M  Age of file in days when script started.
	[...]

So: (date script started - date on file), converted to days.

Why not just stat() the fine and compute on the mtime, which is in
seconds since the epoch? It's also in the FM, under "stat".

===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu