in reply to Using -M to test age of file

Try using stat

Change
my $fileAge = -M $fileName;
to
my $fileAge = (stat($filename))[9];


Update: Looks like it is probably the path being wrong. Apparently these commands do pretty much the same thing internally(which is probably good to know), so just ignore my original answer.

Replies are listed 'Best First'.
Re: Re: Using -M to test age of file
by tachyon (Chancellor) on Aug 22, 2003 at 15:30 UTC

    Try using stat

    Why? You seem to presume that stat and -M are not intimitely related? In fact -X just calls stat and caches the unused result fragments in the _ magical var - yes it is called _ so you can do this:

    $exist = -e $blah; # calls stat, returns -e , caches result $dir = -d _; # takes the last stat (ie $blah) returns -d value $file = -f _; # etc

    The problem is a path issue, the solution is:

    my $fileAge = -M $fileName || die "Can't stat $fileName $!\n"

    The error will be No such file or directory Solution full path. Yes you can make relative work but that is an exercise for the reader.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      In fact -X just calls stat and caches the unused result fragments in the _ magical var - yes it is called _ so you can do this:

      Just to clarify, caching the results isn't peculiar to the filetest operators; stat() itself caches the results too.

      -sauoq
      "My two cents aren't worth a dime.";