简体   繁体   English

多个Perl`print $ cgi-> header,<

[英]multiple Perl ` print $cgi->header, <<HTML; … HTML ` statement gives problem

i have something like: 我有类似的东西:

    #!/usr/bin/perl

use strict;
use warnings;
use CGI::Simple;
use DBI;

my $cgi = CGI::Simple->new;


if ($cgi->param('selid'))
{

    print $cgi->header, <<HTML;
    <br/>this is SELECT 
     HTML
}
elsif ($cgi->param('delid'))
{

    print $cgi->header, <<HTML; 
    <b>this is DELETE</b>
    HTML
}
elsif ($cgi->param('upid'))
{
    print $cgi->header, <<HTML; 
    <b>this is UPDATE</b>
    HTML
}

when i run this i get an error like: 当我运行这个我得到一个错误,如:

Error message: Can't find string terminator " HTML" anywhere before EOF at C:/xampp/htdocs/perl/action.pl line 14. , 错误消息:在C:/xampp/htdocs/perl/action.pl第14行EOF之前的任何位置都找不到字符串终止符“ HTML”。

and when give space between << and HTML; 以及何时在<<HTML;之间<<空格HTML;

like : print $cgi->header, << HTML; 比如: print $cgi->header, << HTML;

error changes to: 错误更改为:

Error message: Can't find string terminator " " anywhere before EOF at C:/xampp/htdocs/perl/action.pl line 14. , 错误消息:在C:/xampp/htdocs/perl/action.pl第14行EOF之前的任何位置都找不到字符串终止符“”,

what would be the reason for this? 这是什么原因?

note: parameters are passed from another page('selid' or 'delid' or 'upid') 注意:参数是从另一个页面传递的(“ selid”或“ delid”或“ upid”)

It is necessary to make sure that the end tag for heredocs is at the beginning of the line or the tag will not be recognized by the interpreter. 必须确保heredocs的结束标记在行的开头,否则解释器将不会识别该标记。 So put the HTML ending at the very beginning of the line, no whitespace before it. 因此,将HTML结尾于该行的开头,在其前面没有空格。

Also keep in mind that using double quotes around the start tag (eg print <<"HTML";) allows variables to be interpolated, using single quotes doesn't and using the tag without either behaves like double quotes 还要记住,在开始标记周围使用双引号(例如,print <<“ HTML”;)可以对变量进行插值,不使用单引号,而不使用标签而使用标记的行为就像双引号一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM