[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] recursive file search subroutine



Dear MacPerl People,

I have naively written a subroutine using recursion to list all files from
the nested folders of my given folder.  However, the routine stops
unexpectedly.  I have run my code using the MacPerl debugger, although I am
still new at navigating through the commands and using the appropriate
options.

Would one of you kind people take a look at my code to see if you can spot
where I went wrong?

**********************************

$basedir = "# place root folder here #";

GetListing ($basedir);

exit;

sub GetListing {
    my $parent = shift(@_);
    my $file = "";
    print "\n\nFor directory \"$parent\:\"\n";

    chdir($parent);
    my @files = <*>;
    
    foreach $file (@files) {
        if ($file =~ m/\w/) {
            if (-f $file) {
                print "$file is a file\.\n";
            }
        
            elsif (-d $file) {
                GetListing ("$parent\:$file");
            }
        }
    }
}

**************************************

--
Robert Terwilliger, M.S.
raterwil@ucla.edu


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org