in reply to Recursive sub
A couple of remarks on top of those of BrowserUK:
1) Perl has an elsif option, so you can simplify you sub thusly:
sub recurseDir2 { my @temp = (glob $_[0]); foreach (@temp) { if (-d $_) { print "Directory: $_" , "\n" ; recurseDir2("$_/*"); } elsif (-f $_) { print "File: $_ \n"; } } }
2) There might (I'm not sure with Windoze) be some 'things' in your directories meet neither the -f nor the -d test. In which case, I would recommend adding an else clause:
sub recurseDir2 { my @temp = (glob $_[0]); foreach (@temp) { if (-d $_) { print "Directory: $_" , "\n" ; recurseDir2("$_/*"); } elsif (-f $_) { print "File: $_ \n"; } else { next; } } }
hth
dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Recursive sub
by dragonchild (Archbishop) on Sep 23, 2003 at 21:07 UTC | |
by Not_a_Number (Prior) on Sep 23, 2003 at 21:52 UTC | |
|
Re: Re: Recursive sub
by wolis (Scribe) on Sep 25, 2003 at 06:04 UTC |