in reply to Read directories' contents, add subdirs back into directory list

Well, for one thing, you're modifying @dirs while iterating through it. I'm not sure how safe that is (though I'm not sure how unsafe it is, either).

More importantly, how deep are you trying to go? Even if you use another collection, the names you get from readdir are relative to their parent. So a readdir on them isn't going to yield any more subdirs. If you really want to recurse, you're going to have to do something different.

Perhaps File::Find would do the trick for you:

use strict; use File::Find; my @dirs = ( '/home/ned', '/usr/games' ); sub doStuff { print shift() . "\n"; } find( sub { doStuff($File::Find::name) unless -d _ }, @dirs );
  • Comment on Re: Read directories' contents, add subdirs back into directory list
  • Download Code