幾個知識點:
use Cwd 引用當前目錄
cwd:當前目錄
shift:獲取位置參數;
chdir 改變目錄位置
opendir 打開目錄
closedir 關閉目錄
foreach 。。。next
#!perl -w use strict; use Cwd; // sub scanDirectory { my $workdir=shift; my $startdir=cwd; chdir $workdir or die "Unable to enter the $workdir dir!\n"; opendir my $DIR,'.' or die "can't open the dir\n"; my @names = readdir $DIR or die "can't readdir\n"; closedir $DIR; foreach my $name(@names){ next if($name eq '.'); next if($name eq '..'); if(-d $name){ scanDirectory($name); next; } if($name eq 'core.txt'){ print "find a core file! Path:". cwd ."\n"; next; } } chdir $startdir or die "Unable to enter the $startdir dir!\n"; } &scanDirectory('.');