GotToBTru has asked for the wisdom of the Perl Monks concerning the following question:
I am not sure if it is File::Find or grep that is responsible for the behavior I see.
use strict; use warnings; use File::Find; my $dir='/home/edi/wlsedi/howard/temp'; find({preprocess => sub { return grep { -M $_ < 1 } @_ }, wanted => sub { printf "%s\n",$_ if (-f $_) } }, $dir);
Output(as expected):
file1 file2 file3
I would rather have the directory case handled in preprocess than wanted.
use strict; use warnings; use File::Find; my $dir='/home/edi/wlsedi/data_backup/univfiledrop'; find({preprocess => sub { return grep { -f $_ && -M $_ < 1 } @_ }, wanted => sub { printf "%s\n",$_ } }, $dir);
Output:
. file1 file2 file3
Why is . included?
File::Find calls the wanted function with the directory name before it performs the readdir() on the directory. The preprocess routine is not called for this invocation.
use strict; use warnings; use File::Find; my $p = 0; my $dir='/home/edi/wlsedi/howard/temp'; find({preprocess => sub { printf "p %d %s\n",$p++,$_; return @_ }, wanted => sub { printf "w %d %s\n",$p++,$_ } }, $dir);
ls -e /home/edi/wlsedi/howard/temp total 0 drwxr-xr-x- 2 wlsedi wlsedi 256 Jul 01 09:33 dirhere -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file1 -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file2 -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file3
Output:
w 0 . p 1 . w 2 file1 w 3 file2 w 4 file3 w 5 dirhere p 6 dirhere
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File test in grep not excluding current directory (chdir)
by tye (Sage) on Jul 01, 2014 at 13:41 UTC | |
by GotToBTru (Prior) on Jul 01, 2014 at 14:14 UTC | |
Re: File test in grep not excluding current directory
by choroba (Cardinal) on Jul 01, 2014 at 13:29 UTC | |
Re: File test in grep not excluding current directory ( use File::Find::Rule qw/ find rule :Age /; )
by Anonymous Monk on Jul 01, 2014 at 15:47 UTC | |
Re: File test in grep not excluding current directory
by Anonymous Monk on Jul 01, 2014 at 13:29 UTC | |
by Anonymous Monk on Jul 01, 2014 at 13:34 UTC |