>>>>> "LY" == Li Yi <liyionline1...@gmail.com> writes:
LY> I have encounter a problem in which i need to scan over all the files LY> within a directory tree. My script is like the following before we get into your code, where are you learning perl? this is very old style perl. it is perl 4 to be exact which is very very old and not used anymore. please upgrade your perl and your learning sources. LY> #!/usr/bin/perl -w use warnings is better. use strict is needed. LY> $d = "some directory here"; LY> chop($d); chomp is the correct call now. LY> &searchDirectory($d); subs don't need to be called with &. LY> sub searchDirectory { LY> local($dir); LY> local(@lines1); LY> local($line); LY> local($subdir); those should be my variables, not local. LY> $dir = $_[0]; my( $dir ) = @_ ; LY> print "$dir\n"; LY> @lines1 = `cd $dir;ls -A|cat`; why are you piping ls to cat? that is a useless use of cat. and you can do that directly in perl. LY> It does not work as expected, for example there are /a/a1/a2, LY> /b/b1/b2, /c/c1/c2, my expectation would be that it scan through all LY> those files, but it turned out that it only work with one LY> subdirectory, and only one sub of the sub.... LY> Can anyone offer some hint? use File::Find which will scan dirs for you. but you must drop perl4 and learn perl5. seriously. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/