in reply to Array Normalization of File::DirWalk
I'm sorry to say it, but File::DirWalk is not a very well written module. To do what you want to do properly, you have to reach into the object, breaking its encapsulation. (Hey, at least it's possible. :-) And the module's documentation is poor, in that it does not tell you what the depth parameter is really for or how it's used.
The following works:
for my $directory ( @directory ) { my $dw = new File::DirWalk; $dw->onDirLeave( sub{ my $dir = shift; if ( $dw->{'depth_count'} == $depth ) { push @folder, $dir; } return File::DirWalk::SUCCESS; } ); $dw->setDepth( $depth + 1 ); $dw->walk( $directory ); }
Note two things:
- The test of the object's data member 'depth_count' against $depth;
- passing $depth + 1 to the setDepth method.
Just for fun, here's how I'd probably write the above:
my $dw = new File::DirWalk; sub on_dir_leave { $dw->{'depth_count'} == $depth and push @folder, shift; File::DirWalk::SUCCESS } $dw->onDirLeave( \&on_dir_leave ); $dw->setDepth( $depth + 1 ); $dw->walk( $_ ) for @directory;
A word spoken in Mind will reach its own level, in the objective world, by its own weight
In Section
Seekers of Perl Wisdom