Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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
Perl:零大小(-z)的文件测试未按预期执行_Perl - Fatal编程技术网

Perl:零大小(-z)的文件测试未按预期执行

Perl:零大小(-z)的文件测试未按预期执行,perl,Perl,我编写了一个脚本,它扫描服务器以查找世界上可写的文件。在脚本的中间是一段代码,用于测试文件的存在性、不存在性或零大小。 # Read in the list of excluded files and create a regex from them if (-e $exclude) { $regExcld = do { open XCLD, "<${exclude}" or die "Cannot open ${exclude}, $!\n"; my @ignore

我编写了一个脚本,它扫描服务器以查找世界上可写的文件。在脚本的中间是一段代码,用于测试文件的存在性、不存在性或零大小。
# Read in the list of excluded files and create a regex from them
if (-e $exclude) {
  $regExcld = do {
    open XCLD, "<${exclude}" or die "Cannot open ${exclude}, $!\n";
    my @ignore = <XCLD>;
    chomp @ignore;
    local $" = '|';
    qr/@ignore/;
  };

} elsif ((! -e $exclude) || (-z $exclude)) {
  $errHeader = <<HEADER;
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                  !!
!! /usr/local/etc/world_writable_excludes.txt is    !!
!! is missing or empty. This report includes        !!
!! every world-writable file including those which  !!
!! are expected and should be excluded.             !!
!!                                                  !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


HEADER

}

问题在于
-e
是您的第一个条件。即使文件大小为0,也是如此。试试
-首先是e
,然后是
-z
,然后是
-e

#!/usr/bin/perl

my $test;

if (-z "/usr/local/etc/world_writable_excludes.txt") {
  $test = "Zero Size";

}

if ($test) {
  print $test . "\n";

}