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

Reply via email to