in reply to More on Stat() vs -A

Wizards,
I'm trying to track down "the last time a file was used." The -A op seems to give what I need. But...
While experimenting with stat() I noticed that it seems to not only reset whatever thingie the -A op uses, but that it also sees *itself* as a "file access," so that every file I run stat($f) on returns just under 1.1 billion seconds--which translates roughly to right now today. Unless it reads the -A as a file access. In either case, if I run one or the other on four-year-old files, after running both I get a zero from -A and the 1.1 billion seconds from stat().
So, what can you in your great wisdom tell me about stat(), about -A, whatever they use, reset, and otherwise foul up?
Thanks!
Reply to: Deane.RothenmaierREMOVETHIS@Walgreens.com

20070729 Edit by ysth: reparented this SoPW under its followup

Replies are listed 'Best First'.
Re: stat($f) vs -A $f
by xorl (Deacon) on Jul 28, 2004 at 21:06 UTC
    That seems odd. What's your OS and version of Perl? On my RH9 default install of Perl
    #!/usr/bin/perl ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$bl +ksize,$blocks)=stat("/tmp/foo.txt"); print localtime($atime) . "\n";
    Returns the last accessed time and does not count as a file access.

    Does your script do anything else with these files?

Re: stat($f) vs -A $f
by bgreenlee (Friar) on Jul 29, 2004 at 10:25 UTC

    Could you post some sample code that shows the strange behavior?

    Keep in mind that -A is the script startup time (which can be found in $^T) minus the file access time--in days. stat returns the absolute last access time in seconds since the epoch.

    The following gets the last access time from a file by both methods. I tried it on three different OSs (OS X, WinXP, and RH 9), and the results are the same.

    # do it with stat my $atime = (stat($ARGV[0]))[8]; print "stat says: ", scalar localtime $atime, "\n"; # do it with -A $atime = $^T - (-A $ARGV[0]) * 86400; print "-A says: ", scalar localtime $atime, "\n";

    Brad