in reply to Recursive sub
That said, you have a few "issues" with your code. Try the following:
use File::Spec; my $dir = "C:\"; sub recurseDir2 { foreach (glob shift) { if (-d) { print "Directory: '$_'\n" ; recurseDir2(File::Spec->catfile($_, '*')); next; } if (-f) { print "File: '$_'\n"; } } } recurseDir2($dir)
I wasn't able to reproduce your problem, but I think I know where it might have come from. You're on a Windows system, but using the Unix directory syntax. This is why modules exist, to make sure you don't get screwed up. File::Spec will make sure you use the right directory separator for your system. This isn't "stealing code" - this is intelligent re-use of well-thought out solutions.
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Recursive sub
by pen (Acolyte) on Sep 23, 2003 at 19:27 UTC | |
by LazerRed (Pilgrim) on Sep 23, 2003 at 20:29 UTC |