3
我试图找出如何使用Perl中的定界符来创建一个简单的HTML文件,但我不断收到创建HTML文件失败,裸字错误
Bareword found where operator expected at pscratch.pl line 12, near "<title>Test"
(Missing operator before Test?)
Having no space between pattern and following word is deprecated at pscratch.pl line 13.
syntax error at pscratch.pl line 11, near "head>"
Execution of pscratch.pl aborted due to compilation errors.
我想不出问题是什么。这是全部的脚本:
use strict;
use warnings;
my $fh;
my $file = "/home/msadmin1/bin/testing/html.test";
open($fh, '>', $file) or die "Cannot open $file: \n $!";
print $fh << "EOF";
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>This is a test</h1>
</body>
</html>
EOF
close($fh);
我周围使用EOF
单引号和双引号尝试。我也尝试转义所有<>
标签,但没有帮助。
我该怎么做才能防止这个错误?
编辑
我知道有模块,在那里,将简化这一点,但我想知道是什么问题,与此之前,我简化了模块的任务。
EDIT 2
的错误似乎表明,Perl是看定界符内的文本作为替代由于在结束标记的/
。如果我将它们转义出来,那么错误的一部分就会消失,但是其余的错误依然存在。
删除空间后''<<。 – melpomene
谢谢!请做出答案,以便我可以选择它。 – theillien
有了这个空间,它是一个移位操作http://perldoc.perl.org/perlop.html#Shift-Operators,所以Perl将HTML解释为Perl代码 – ysth