Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Anonymous Monk
on Sep 18, 2004 at 23:09 UTC ( #392063=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am getting this error message when I try to compile this file.

ERROR MESSAGE = Can't find string terminator "ENDHEADER" anywhere before EOF
#!/usr/bin/perl sub print_chat { print <<ENDHEADER; Content-type: text/html <html> <head><title>My Chat</title> </head> </html> ENDHEADER } return 1;

Comment on Can't find string terminator "ENDHEADER" anywhere before EOF
Select or Download Code
Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by Enlil (Parson) on Sep 18, 2004 at 23:19 UTC
    It should work fine as written provided that ENDHEADER is at the very start of a line and nothing else follows it (though I can't tell for sure as you should put <code> tags around your code so we can also see your code formatting which is important in this case). As per perlop:

    The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.

    HTH

    -enlil

      Yes, he's right. The end tag has to be by itself on the line. Here's your code without errors:
      sub print_chat { print <<ENDHEADER; Content-type: text/html <html> <head><title>My Chat</title> </head> </html> ENDHEADER } return 1
      (though I don't understand why return 1 is outside the end } ?)
        This is usually because there are spaces before "ENDHEADER" There should not be spaces before second ENDHEADER. Regards, Ivan
        serioulsy its working out... there should be any space between 2nd ENDHEADER.. generally we keep tab and type. thats the exact mistake
Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by Errto (Vicar) on Sep 19, 2004 at 00:27 UTC
    From the HTML source for your post, it looks like the word "ENDHEADER" in your code is indented, and thus has some whitespace on the beginning of the line. Delete that and it should work.
Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by The Mad Hatter (Priest) on Sep 19, 2004 at 01:50 UTC

    Another option is to change the delimeter to fit what you have instead of the other way around:

    sub print_chat { print <<" ENDHEADER"; Content-type: text/html <html> <head><title>My Chat</title> </head> </html> ENDHEADER } return 1;

    Also, wouldn't the return make more sense inside the sub?

Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by Anonymous Monk on Sep 19, 2004 at 06:17 UTC
    use diagnostics; print <<FOOOBAR; __END__ Can't find string terminator "FOOOBAR" anywhere before EOF at - line 2 + (#1) (F) Perl strings can stretch over multiple lines. This message me +ans that the closing delimiter was omitted. Because bracketed quotes +count nesting levels, the following is missing its final parenthesis: print q(The character '(' starts a side comment.); If you're getting this error from a here-document, you may have in +cluded unseen whitespace before or after your closing tag. A good program +mer's editor will have a way to help you find these characters. Uncaught exception from user code: Can't find string terminator "FOOOBAR" anywhere before EOF at +- line 2.
Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by quai (Novice) on Sep 19, 2004 at 19:10 UTC
    (when you correct this bug, and wonder why you get an 505 error, add a empty line after the Content-type-line)
Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by Anonymous Monk on Sep 20, 2004 at 14:27 UTC
    First, try removing the tab/whitespace before your terminator (i.e. ENDHEADER). Second, your return is in the wrong block. should look more like this:
    #!/usr/bin/perl sub print_chat { print <<ENDHEADER; Content-type: text/html <html> <head><title>My Chat</title> </head> </html> ENDHEADER return 1; }

    20040920 Janitored by Corion: Added code tags

Re: Can't find string terminator "ENDHEADER" anywhere before EOF
by Anonymous Monk on Sep 20, 2004 at 18:56 UTC
    IIRC, you have to un-indent the ending ENDHEADER tag so there's no whitespace before or after it.
      That Perl says: "Can't find string terminator "" anywhere before EOF" instead of: "Help! There's some whitespace before the second one" is: TRULY PATHETIC
        to be fair, if you place: use diagnostics; at the start of the code it will say: "If you're getting this error from a here-document, you may have included whitespace before or after your closing tag. A good programmer's editor will have a way to help you find these errors."
        The behaviour can't be changed because of backwards compatibility. The best that can be done is too clearly document the trap, and that has been done. Perl 6, not constrained by backwards compatibility, does allow whitespace before the token.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://392063]
Approved by Old_Gray_Bear
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2014-09-03 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls