http://www.perlmonks.org?node_id=71770


in reply to (tye)Re: Recursive opendir without
in thread Recursive opendir without

No, it's not a problem of "/" (even if my first exemple could be wrong).
I mean : if I take ton's code and replace $dh by $dir :
use strict; # ---> IMPORTANT my $dir = "toto"; my $file; sub openNewDir { my $dir = shift; ### my $dh; opendir ($dir, $dir); # ---> MODIFICATION while ($file = readdir ($dir)) { # ---> MODIFICATION here too next if (($file eq '.') || ($file eq '..')); if (-d "$dir/$file") { openNewDir("$dir/$file"); } else { # Do something with the file print "($file)\n"; } } close ($dir); # ---> MODIFICATION here too } openNewDir ($dir);
(I comment important lines).
use strict warm me : Can't use string ("toto") as a symbol ref while "strict refs" in use at test.pl line 13. (that mean during the readdir()).
And when I was trying to explain you, I think I understood why ;) (but not sure)
It could be that readdir() don't know if $dir is a "Directory Handler" or the "Directory" itself...

BoBiOne