I have encounter a problem in which i need to scan over all the files within a directory tree. My script is like the following

#!/usr/bin/perl -w
$d = "some directory here";

chop($d);
&searchDirectory($d);

sub searchDirectory {
    local($dir);
    local(@lines1);
    local($line);
    local($subdir);

    $dir = $_[0];
    print "$dir\n";
    @lines1 = `cd $dir;ls -A|cat`;
    foreach (@lines1){
# do something here
    }


    @lines2 = `cd $dir;ls -l`;
    foreach $line (@lines2) {

        if($line =~ /^d/) {
        $line =~ /\s+(\S+)$/;
        $subdir = $dir."/".$1;


&searchDirectory($subdir)

        }
    }
}

It does not work as expected, for example there are /a/a1/a2, /b/b1/b2, /c/c1/c2, my expectation would be that it scan through all those files, but it turned out that it only work with one subdirectory, and only one sub of the sub....

Can anyone offer some hint?


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to