Perl 运行中遇到的问题 报错:Can't find string terminator "End_of_HEAD"

potato1234 potato1234 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面是我的程序:
#! 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行报错,也不知道是什么原因
...全文
评论 3
收藏 已收藏
分享
返回顶部
potato1234
脚本语言 37,738 成员 34,208 内容