-1

嗨,我刚刚IF在我的源代码中添加了一个条件,从那以后我收到了错误

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

但如果我删除它,它会起作用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;
4

2 回答 2

6
    _HTML_
}
exit;

应该

_HTML_
}
exit;

但是,请不要在if.

作为更好的选择,请执行以下操作:

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

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

于 2013-04-07T10:22:11.677 回答
4

HEREDOC 在整行上查找匹配项。它不会忽略前导空格。你需要:

    print<<_HTML_;
        bla
_HTML_

您还可以使制表符/空格成为 HEREDOC 字符串的一部分:

    print<<"    _HTML_";
        bla
    _HTML_
于 2013-04-07T10:19:50.980 回答