Perl 运行中遇到的问题 报错:Can't find string terminator "End_of_HEAD"
下面是我的程序:
#! usr/bin/perl -w
use warnings;
use strict;
if (@ARGV != 3) {
# 使用HereDoc的语法,在输入参数不对的时候输出使用方法
# HereDoc从<<"END_OF_USAGE";的下一行开始,一直到第一个顶格的END_OF_USAGE
die <<"END_OF_USAGE";
Usage:
$0 <source_dir> <extension> <target_word>
source_dir Directory containing the files.
extension The extension (without dot '.') of the file to be edited.
target_word
END_OF_USAGE
}
# 将传入参数转储到命名参数中
my ($source_dir, $extension,$target_word) = @ARGV;
$extension =~ s/^\.//g;
# 打开指定的文件夹,将文件夹句柄保存在局部变量 $dh 里。 dh - Directory Handle
opendir my $dh, $source_dir or die "Cannot open $source_dir: $!";
my @list = grep { /\.$extension$/ && -f "$source_dir/$_" } readdir $dh;# 从文件名列表@list里面逐个选出文件名,使用$file作为别名引用单个文件名
closedir $dh;
for my $file (@list) {
open my $fh, '<', "$source_dir/$file" or warn "Cannot open file $source_dir/$file: $!";
while (<$fh>) {
if (index($_, $target_word) >= 0) {
print <<'END_OF_HEAD';
<html>
<head>
<title>"$source_dir/$file"</title>
<style type="text/css">
.highlight {
color: red;
font-weight: bold;
font-size: 16pt;
}
</style>
</head>
<body>
END_OF_HEAD
while (<>) {
s/$target_word/<span class="highlight">$target_word<\/span>/g;
s/\n/<br \/>\n/;
s/^( +)/' ' x (length $1)/e;
print;
}
print <<'TAIL_OF_FILE';
</body>
</html>
TAIL_OF_FILE
}
}
close $fh;
}
第30行报错,也不知道是什么原因