为什么我的Perl脚本在EOF之前的任何地方都给出错误“找不到字符串终结符”_HTML_?

时间:2013-04-07 10:15:21

标签: perl cgi heredoc

您好我刚刚在我的源代码中添加了IF条件,从那时起我就收到了错误

  

“在EOF之前的任何地方找不到字符串终止符_HTML_

但如果我删除了IF

,它就有效

我是Perl和CGI的新手,我不知道如何解决这个错误。

这是我的代码:

#!"\xampp\perl\bin\perl.exe"

use CGI qw/:standard/;
use CGI::Cookie;

%cookies = CGI::Cookie->fetch;
$Cookie = $cookies{'USER'}->value;


if ($Cookie)
{

    print "Content-type: text/html\n\n";
    print<<_HTML_;

    <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
    <!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
    <!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
    <!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
        <head>
            <meta charset="UTF-8" />
            <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
            <title>Login and Registration Form with HTML5 and CSS3</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

            <link rel="shortcut icon" href="../favicon.ico"> 
            <link rel="stylesheet" type="text/css" href="css/loginpage.css" />
            <link rel="stylesheet" type="text/css" href="css/style.css" />
            <link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
        </head>
        <body>
            <div class="container">
                <header>
                    <h1>User's Login Panel</h1>

                    <span>Enter your details below</span>
                </header>
                <section>               
                    <div id="container_demo" >

                        <a class="hiddenanchor" id="toregister"></a>
                        <a class="hiddenanchor" id="tologin"></a>
                        <div id="wrapper">
                            <div id="login" class="animate form">
                                <form  action="/cgi-bin/Project/logincheck.pl" method="post" autocomplete="on"> 
                                    <h1>Log in</h1> 
                                    <p> 
                                        <label for="username" class="uname" data-icon="u" > Your email or username </label>
                                        <input id="username" name="username" required type="text" placeholder="myusername or mymail@mail.com"/>
                                    </p>
                                    <p> 
                                        <label for="password" class="youpasswd" data-icon="p"> Your password </label>
                                        <input id="password" name="password" required type="password" placeholder="eg. X8df!90EO" /> 
                                    </p>
                                    <p class="keeplogin"> 
                                        <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> 
                                        <label for="loginkeeping">Keep me logged in</label>
                                    </p>
                                    <p class="login button"> 
                                        <input type="submit" value="Login" /> 
                                    </p>
                                    <p class="change_link">
                                        Trouble Logging in?
                                        <a href="#toregister" class="to_register">Reset Your Password </a>
                                    </p>
                                </form>
                            </div>

                            <div id="register" class="animate form">
                                <form  action="mysuperscript.php" autocomplete="on"> 
                                    <h1>Trouble Logging In?</h1> 

                                    <p> 
                                        <label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
                                        <input id="emailsignup" name="emailsignup" required type="email" placeholder="mysupermail@mail.com"/> 
                                    </p>

                                    <p class="forgotpass "> 
                                        <input class="buttonpass" type="submit" value="Send Password Reset Instructions"/> 
                                    </p>
                                    <p class="change_link">  
                                        Oh Wait My Brain Cells Started Tickling!
                                        <a href="#tologin" class="to_register"> Go and log in </a>
                                    </p>
                                </form>
                            </div>

                        </div>
                    </div>  
                </section>
            </div>
        </body>
    </html>

    _HTML_
}
exit;

2 个答案:

答案 0 :(得分:6)

    _HTML_
}
exit;

应该是

_HTML_
}
exit;

但是,请不要在if的中间放置一大块HTML。

作为一个更好的选择,请执行:

use constant _HTML_ => <<_HTML_;
   <!DOCTYPE html>
    <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
...
_HTML_

作为一个更好的选择,完全将内容与代码分开。

答案 1 :(得分:4)

HEREDOC在整条线上寻找一场比赛。它不会忽视领先的空间。你需要:

    print<<_HTML_;
        bla
_HTML_

您也可以将标签/空格作为HEREDOC字符串的一部分:

    print<<"    _HTML_";
        bla
    _HTML_