randian has asked for the wisdom of the Perl Monks concerning the following question:
This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-linux
use strict; use warnings; use 5.010; use File::Find qw/find/; my @all; my @insub; my @outsub; my $dir = 'static'; find sub { my $f = $File::Find::name; push @all, $f; return if -d $f; push @insub, $f; }, $dir; @outsub = grep {!-d} @all; my $all_count = @all; my $insub_count = @insub; my $outsub_count = @outsub; say 'all_count = ', $all_count; say 'insub_count = ', $insub_count; say 'outsub_count = ', $outsub_count;
$dir should be set to a directory that has a little bit of depth to it.
What I expect is that $insub_count should match $outsub_count. What I get is $insub_count matching $all_count;
all_count = 436 insub_count = 436 outsub_count = 408
If you change the sense of the test in the sub to
return if ! -d $f
$insub_count becomes 0!
Similar bizarre behavior occurs with -f.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problem with -d inside find sub
by moritz (Cardinal) on Apr 26, 2012 at 20:27 UTC | |
by randian (Acolyte) on Apr 27, 2012 at 01:01 UTC | |
by Anonymous Monk on Apr 27, 2012 at 02:28 UTC | |
by randian (Acolyte) on Apr 27, 2012 at 09:34 UTC | |
by Anonymous Monk on Apr 27, 2012 at 14:31 UTC | |
by randian (Acolyte) on Apr 27, 2012 at 09:34 UTC | |
by Anonymous Monk on Apr 27, 2012 at 12:01 UTC | |
by randian (Acolyte) on Apr 27, 2012 at 14:18 UTC | |
by Anonymous Monk on Apr 28, 2012 at 11:33 UTC |
Back to
Seekers of Perl Wisdom