我想用Perl檢查一個目錄是否存在於UNIX系統中。用Perl檢查一個目錄是否存在
while (my @row = $sth->fetchrow_array) {
my $id = $row[0];
my $hash = $row[1];
my $direction = '/home/users/' . $hash
if(-d $direction){
print "$direction exists";
}
}
但我得到這個錯誤:
Global symbol "$direction" requires explicit package name at Perl.pl line 31. syntax error at Perl.pl line 31, near "){" syntax error at Perl.pl line 35, near "}" Execution of Perl.pl aborted due to compilation errors.
線31在這種情況下是:
if(-d $direction)
任何想法?
使用'strict'的好工作! :) – simbabque