in reply to Hard to find bug in my File::Find code

Looking at the code, as soon as you encounter "shared", you increase $depth by one. But as soon as you see any directory in home it will skip the first case of your if because the $depth is not the original depth, and will subtract from $depth. So while you're exploring "shared", $depth keeps on bouncing back and forth.

It gets more complicated if you visit 2 special directories in a row. In your case you visit /shared/ITReg and add to $depth, but that is the last /shared/* directory. Therefore when you enter /home, $depth decreases by one and you get /home rather than subdirectories.

The solution is that rather than trying to manipulate a global $depth as you walk the tree, within each invocation of &wanted calculate $depth from first principles.

  • Comment on Re: Hard to find bug in my File::Find code

Replies are listed 'Best First'.
Re^2: Hard to find bug in my File::Find code
by Zenshai (Sexton) on Aug 29, 2008 at 20:03 UTC
    So I'd need another variable, lets say $curr_depth which would be calculated at the start of a &wanted call, and then I can update the $depth global with it at the end of the call? Am I getting this right?

    The reason its global now is so I can share it with &preprocess...