Yes, thanks a lot, I know I can use the find.pm package. But, I wantted
to learn what did I do wrong about my code.

I'd be mostly thankful for you inputs,
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 

-----Original Message-----
From: Dave Gray [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 17, 2004 7:39 PM
To: Eaton Elyahu Doron
Cc: [EMAIL PROTECTED]
Subject: Re: Recursive function

>   The purpose is simple, search directory inside $depth levels for 
> directories.

No need to reinvent the wheel:
 <http://search.cpan.org/~nwclark/perl-5.8.5/lib/File/Find.pm>
______________________________________________________________________
  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>


Reply via email to