in reply to Re: How to open file inside loops with file names generated using an array?
in thread How to open file inside loops with file names generated using an array?

Opening and manipulating files within a loop that is also finding them can cause problems in some environments.

wat? examples please

  • Comment on Re^2: How to open file inside loops with file names generated using an array?

Replies are listed 'Best First'.
Re^3: How to open file inside loops with file names generated using an array?
by Anonymous Monk on May 29, 2018 at 14:41 UTC
    It depends on the operating system, but a file-finder can skip file entries or see the same entry more than once ... a problem that is neatly avoided by completely scanning, say, a particular directory, then processing that list before moving on to the next one. (I have not looked closely at Perl's implementation of file-finders, but in other languages I noticed them doing this internally, and wondered why they did it that way.) Particularly if you are inserting, deleting, or renaming entries in the designated container, this approach can avoid a lot of messy problems.
      If you are merely reading or updating the files, it usually doesn't matter. Troubles start when you are changing the list-of-files or file-names underneath the walker's feet while it's walking.