in reply to foreach vs. while inside a directory tranversing subroutine

Not directly related to the foregoing (and, promptly up-voted) explanation, I’d like to add two tangental comments with regard to the general subject of traversing directory structures:

(1)   Particularly in the Windows operating-system, I have over the years encountered various problems such as limits on the number of directory searches you could actually successfully do at one time.   (Deeply nested directory structures started throwing OS-errors as, apparently, Windows ran out of a limited resource.   Explicitly closing the cursors was also very important.)   Therefore, it was necessary to use a “to-do list” of my own making.   But in any case, you don’t have to futz with things like that, since there are a-plenty of known-good routines (e.g. File::Find) in CPAN, which have been tested against very deep structures.   You probably should use these routines in preference to your own, especially if you deal with Windows.   You can encounter “gotchas,” otherwise, which are nothing more than time-and-money wasters.

(2)   Also in the same vein, and also on Windows, I have encountered unexpected problems with directory searches (skipping entries, finding entries more than once, OS errors) when I attempted to do something with the files that were found (and especially, anything-at-all to do with directories), within the traverse loop.   Therefore, I categorically advise, “first do one, then do the other.”   Traverse to accumulate a to-do list, then separately process the list.   That always does the job without interference.

Replies are listed 'Best First'.
Re^2: foreach vs. while inside a directory tranversing subroutine
by Anonymous Monk on May 26, 2015 at 12:00 UTC
    File::Find ... tested against very deep structures.

    How deep exactly are the directory structures that File::Find is tested against?