It uses the directory entries in the order that the system call readdir(3C) returns them in. This is related to their device number and inode, I believe. It's some particular order, although I'm not sure what order it is.
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??; | [reply] |
Is there any way to sort what find returns by the time
stamp?
| [reply] |
#!/usr/bin/perl -w
use strict;
use File::Find;
my @files;
sub wanted {
push @files, [ $File::Find::name, -M $_ ];
}
find(\&wanted, "/tmp");
foreach (sort {$a->[1] <=> $b->[1]} @files) {
print $_->[0], "\n";
}
As you can see, within the wanted function, we collect each filename and the time it was last modified. Once find() finishes, we then sort the files into the desired order and print them out. | [reply] [d/l] |
See the preprocess argument -- if you pass a code reference, it'll apply it to the list returned by readdir before calling your wanted coderef. Something like this, perhaps:
find({ wanted => \&wanted, preprocess => sub {
sort { -M $a <=> -M $b } @_;
},
}, '.');
| [reply] [d/l] [select] |
When in doubt, RTFS. Specifically, _find_opt
and _find_dir are what does the real work.
less `perl -MFile::Find -le 'print $INC{"File/Find.pm"}'`
| [reply] [d/l] |
Ouch. perldoc -m File::Find.
| [reply] [d/l] |