Oddity with Find::File and -M

D

Dave Saville

I am having problems with Find::File and -M _ in that I get different
values for directories depending on whether I process files or not.

use strict;
use warnings;
use File::Find;
my $d = shift || '';
#print time(), "\n";
$^T=1293201891; # fix basetime to keep numbers the same between runs
find(\&notwanted, '.');
exit;
sub notwanted
{
return if m/^\.$/; # Don't need '.'
return if $d && ! -d; # only directories
print $File::Find::dir,' ',$File::Find::name,' ',$_, ' ', -M _, " ";
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
$mtime, $ctime, $blksize, $blocks) = stat $_;
printf "%20.17f\n", ($^T-$mtime)/86400; # convert mtime to format of
-M
}

File structure:

<somedir>
<dir1>
<dir2>

chdir'ed to <somedir>

[T:\tmp\test]../try.pl
.. ./dir1 dir1 0.00149305555555556 0.00167824074074074
../dir1 ./dir1/stuff1 stuff1 0.00533564814814815 0.00533564814814815
.. ./dir2 dir2 0.00533564814814815 0.00149305555555556
../dir2 ./dir2/stuff2 stuff2 0.00140046296296296 0.00140046296296296

[T:\tmp\test]../try.pl d
.. ./dir1 dir1 0.00167824074074074 0.00167824074074074
.. ./dir2 dir2 0.00149305555555556 0.00149305555555556

It looks as if the -M _ reported for a directory is not the same as
stat'ing it when files are processed. It would appear to have the
mtime of the last processed file. BTW it makes no difference if I use
find() or finddepth().

Or, as usual, am I missing something?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top