in reply to recursive sub

Well, there are a few different ways to go about this. You could possibily use File::Find to accomplish that. If not, here is a sub that should work too.
#!/usr/bin/perl -w use Cwd; use strict; sub ScanTree { my $startdir = shift; # grab startdir as param passed to sub my $initdir = &cwd; # grab current working directory (see below +) chdir( $startdir ) or die "Unable to enter $startdir: $!\n"; opendir( DIR, "." ) or die "Unable to open $startdir: $!\n"; my @names = readdir( DIR ) or die "Unable to read $startdir: $!\n" +; close( DIR ); foreach my $name( @names ) { next if( $name eq "." ); next if( $name eq ".." ); if( -d $name ) { &ScanTree( $name ); next; } } # return user to saved current working directory (see above) chdir( $initdir ) or die "Unable to enter $initdir: $!\n"; } &ScanTree( "." );

Hope this is what you were looking for.

-loc

Replies are listed 'Best First'.
Re: Re: recursive sub
by tachyon (Chancellor) on Oct 27, 2001 at 16:00 UTC

    Have you considered what potentially happens to your sub if you strike a symbolic link-link-link-link-link-link? You need a -l test in there to avoid following sym links or you will quite probably end up going infinite. Also while -w is generally fine warnings get triggered if you have a recursive sub that recurses more than 100 levels deep if I recall correctly.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print