in reply to Recursion not working

It looks like I'm loosing my directory handle but I can't figure out why.

DIR is a global filehandle. When you recurse, you re-use that same global directory handle and the previous level's use of it gets over-written.

You have two options:

  1. Use lexical handles: In place of DIR & FILE use:
    opendir( my $dh, $dir) or die $!; while ($file = readdir( $dh )) ... open( my $fh, $FullName) or die ...
  2. Or localise those global handles: Add the following to the top of your sub
    sub ScanDir { local( DIR, FILE ); ...

One requires minimum changes; the other is seen as the "Modern" option. Both will work.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?