-1

Hi I have just added an IF condition into my source and since then i am getting the error

"Can't find string terminator _HTML_ anywhere before EOF "

But it works if I remove the IF

I am new to both Perl and CGI and I do not know how to resolve this error.

Here's my Code:

#!"\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;
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Saurabh Sharma
  • 2,422
  • 4
  • 20
  • 41

2 Answers2

6
    _HTML_
}
exit;

should be

_HTML_
}
exit;

But, please don't put a giant chunk of HTML in the middle of an if.

As a slightly better alternative, do:

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

As a much better alternative, completely separate code from content.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • That Worked @Sinan Thanks a Lot! But the Problem is that i am getting this error now: Can't call method "value" on an undefined value at C:/xampp/htdocs/Project/index.pl line 10 I am Retrieving cookies from `$Cookie = $cookies{'USER'}->value;` but don't know whats the error – Saurabh Sharma Apr 07 '13 at 10:32
  • You should open a new question for a new issue. – Sinan Ünür Apr 07 '13 at 16:36
4

The HEREDOC looks for a match on the entire line. It does not ignore the leading space. You'd need:

    print<<_HTML_;
        bla
_HTML_

You could also make the tab/space a part of the HEREDOC string:

    print<<"    _HTML_";
        bla
    _HTML_
Tim
  • 13,904
  • 10
  • 69
  • 101