Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Array Normalization of File::DirWalk

by jdporter (Canon)
on Feb 23, 2007 at 12:26 UTC ( #601732=note: print w/ replies, xml ) Need Help??


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:

  1. The test of the object's data member 'depth_count' against $depth;
  2. 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


Comment on Re: Array Normalization of File::DirWalk
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://601732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-01 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (36 votes), past polls