in reply to Recursive sub
The first problem is that the code you posted doesn't compile:
P:\test>perl -c -mstrict -w junk.pl Scalar value @_[0] better written as $_[0] at junk.pl line 6. syntax error at junk.pl line 5, near "sub recurseDir2 " Can't use global @_ in "my" at junk.pl line 6, near "glob @_" syntax error at junk.pl line 17, near "}" junk.pl had compilation errors.
If you correct the missing semicolon on the first line, the use of @_[0] instead of $_[0] in the third and the ommission of the '2' in the subname in the 7th line, it appears to work fine.
Adding -w and use strict isn't obligatory, but it would probably have saved your need to post this question.
#! perl -w use strict; my $dir = "C:/"; sub recurseDir2 { my @temp = (glob $_[0]); foreach (@temp) { if (-d $_) { print "Directory: $_" , "\n" ; recurseDir2("$_/*"); }else{ if (-f $_) { print "File: $_ \n"; } } } } recurseDir2($dir)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Recursive sub
by pen (Acolyte) on Sep 23, 2003 at 19:40 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2003 at 20:39 UTC | |
|
Re: Re: Recursive sub
by pen (Acolyte) on Sep 23, 2003 at 19:47 UTC | |
by BrowserUk (Patriarch) on Sep 23, 2003 at 21:03 UTC | |
by pen (Acolyte) on Sep 24, 2003 at 00:14 UTC |