0

以下是我用来将 HTML 页面作为分块响应发送的脚本的一部分。但是,在运行脚本时会引发编译错误,例如:

在 nph-99_1_1_18.pl 第 19 行,靠近“print”233“(可能是从第 18 行开始的失控的多行“”字符串)处找到操作员预期的数字

#! /usr/bin/perl

print "HTTP/1.1 200 OK\n";
print "Connection: Close\n";
print "Content-type:text/html\n" ;
print "Transfer-Encoding:chunked\n\n" ;
print "96\r\n";
print <<EndText;
<html>
  <!-- this chunk is 150 bytes in length-->
  <head>
         <title>Document Title</title>
  <link REL="StyleSheet" TYPE="text/css" HREF="example.css">
  </head>

<body>
EndText
print "\r\n\";
print "233\r\n";
print <<EndText;
<!-- this chunk is 563 bytes in length-->
<h1 CLASS="funkyclass" ALIGN="center">Welcome to my home page!</h1>
  <br><br>
<p>Hi there! If you are reading this then you have found my home page!  Congratulations! I know it can be hard to find my pages, but I bet that you feel lucky now. Now that you are here, please take a look at my page of links to <a HREF="http://www.mysite.com/coolsites.html">cool sites</a> or sign my <a HREF="http://www.mysite.com/guestbook.html">guest book</a></p>
<div CLASS="foo"> My wonderful poetry <br> is available if you are REALLY bored. Why not give it a spin?</div>
EndText
print "\r\n\";
4

1 回答 1

1

\你的一个陈述中有一个间接的反对print意见。还有一个你也复制了那条线。它转义了关闭",因此它之后的所有内容都被解释为字符串。

<body>
EndText
print "\r\n\"; # <--- HERE (and also further down)
print "233\r\n";

您是否使用具有语法突出显示的编辑器/IDE 编写代码?打开它并使琴弦伸出。这样,它会在"作为字符串转义后突出显示您的所有内容,并且您不会再次忽略这一点。

此外,您应该use strictuse warnings

于 2013-01-30T19:18:07.850 回答