我正在尝试测试反引号输出字符串(它是字符串,对吗??)是否包含子字符串。
my $failedCoutner = 0;
my $tarOutput = `tar -tvzf $tgzFile`;
print "$tarOutput\n";
my $subStr = "Cannot open: No such file or directory";
if (index($tarOutput, $subStr) != -1)
{
push(@failedFiles, $tgzFile);
$failedCounter++;
print "Number of Failed Files: $failedCounter\n\n\n";
}
print "Number of Failed Files: $failedCounter\n\n\n";
但这行不通。它从不进入 if 语句。
反引号输出:
tar (child): /backup/Arcsight/EDSSIM004: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Number of Failed Files: 0
显然子字符串在第一行。为什么不认这个??