I sent it again, since I didn't got a reply that satisfy me. I know I can use the "find.pm". But, I'd like to know why the recoursive I did is wrong.
Thanks, Eli. -----Original Message----- From: Eaton Elyahu Doron [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 16, 2004 9:44 PM To: [EMAIL PROTECTED] Subject: Recursive function Hi all, Why is the following won't work recursively ? The purpose is simple, search directory inside $depth levels for directories. But since the stop recursive is when depth is "0", after the search starts the first directory it stops when it reaches the level in that first directory and doesn't continue to the next one. I though I declared it as "my" so any callback restarting it ! Your answers will be appreciated, Eli. == Start of code #!/usr/bin/perl my (@dirs,$d,$depth) ; $depth = 2 ; @dirs = &find_dirs ($ARGV[0],$depth) ; print "\n\nOutput is ...\n" ; foreach $d (@dirs) { print ".... $d\n" ; } 1 ; sub find_dirs { my ($dir,$depth) = @_ ; my (@dirs,$d,$exit_status) ; my ($dir_ls) = "dir /AD" ; if ($depth > 0) { $depth-- ; chdir ($dir) ; $exit_status = `dir` ; print "\nCurrently in ----- >\n$exit_status\n==================================\nDepth ($depth)\n" ; open (DIR_LS,"$dir_ls |") ; while (<DIR_LS>) { next if /^\s+/ ; chmop; $d = $_ ; $d =~ s/.*<DIR>\s+// ; $d =~ s/\s//g ; next if ($d =~ /\.\.?/) ; next if ($d =~ /^Export/) ; print "Collecting .... $d\n" ; push (@dirs,$d) ; &find_dirs ($d,$depth) ; } close DIR_LS ; } return @dirs ; } === End of code ______________________________________________________________________ This email message has been scanned by PineApp Mail-Secure and has been found clean. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>