Opening and manipulating files within a loop that is also finding them can cause problems in some environments.
wat? examples please | [reply] |
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.
| [reply] |
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.
| [reply] |