Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用Perl检查目录是否存在_Linux_Perl - Fatal编程技术网

Linux 使用Perl检查目录是否存在

Linux 使用Perl检查目录是否存在,linux,perl,Linux,Perl,我试图用Perl检查UNIX系统中是否存在目录 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"; } } 但我得到了这个错误: 全局符号“$directi

我试图用Perl检查UNIX系统中是否存在目录

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";
    }

}
但我得到了这个错误:

全局符号“$direction”要求在 Perl.pl第31行。Perl.pl第31行附近的语法错误 “”“{”在Perl.pl第35行的执行“}”附近出现语法错误 由于编译错误,Perl.pl被中止

在这种情况下,第31行是:

if(-d $direction)
有什么想法吗

my $direction = '/home/users/' . $hash

此行缺少分号,导致编译错误。

如果在块的开头(
near”){
if
除非
while
直到
for
foreach
when
语句中,检查前面的语句是否缺少分号(

类似地,如果在C-style for语句(
for(…;…;…;;){…}
)的分号(
附近“
)处出现语法错误,请检查前面的语句是否缺少分号(


如果你想写

f();
if (g()) { h() }
但是你写

f()
if (g()) { h() }
Perl认为在块之前缺少一个分号

f()
if (g()) HERE { h() }
因为以下内容在Perl中是有效的:

f() if (g())

很好地使用了
严格的
!:)