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

potato1234 2011-06-09 07:47:50
下面是我的程序:
#! 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行报错,也不知道是什么原因
...全文
273 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
potato1234 2011-06-09
  • 打赏
  • 举报
回复
不好意思呀,我以为写得详细一些,别人可能能看得明白一些。我不太会编辑自己的贴子。
potato1234 2011-06-09
  • 打赏
  • 举报
回复
怎么编辑呀
iambic 2011-06-09
  • 打赏
  • 举报
回复
乱七八糟的。自己把代码精简到十行以内。

37,722

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧