#!/usr/bin/perl
use strict;
use warnings;
open(TEST, "leet.txt") or die "Can't open leet.txt: $!\n";
while(my $line = <TEST>) {
if($line =~ tr/34/ea/)
print <<EOF;
$line
EOF
}
它会产生这样的结果: 语法错误位于 ./practice.pl 第 11 行,靠近“) 打印” 由于编译错误,./practice.pl 的执行中止。
最佳答案
您必须将 if
命令包含在 { }
block 中,即使它只有一个命令。与其他语言不同,在 Perl 中,这不是可选的。
if($line =~ tr/34/ea/) {
print <<EOF;
$line
EOF
}
关于perl - perl 中的这个编译错误是什么?我没有看到语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7113373/