Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

String terminator problems.

by maddfisherman (Sexton)
on Jun 21, 2001 at 04:05 UTC ( [id://90260]=perlquestion: print w/replies, xml ) Need Help??

maddfisherman has asked for the wisdom of the Perl Monks concerning the following question:

I put this in my cgi-bin
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); print "Content-type:text/html\n\n"; print <<'EndHTML'; <html> <head> <title>Fish Report</title> </head> </body> </html> EndHTML
Shouldn't it send out an html page? Why doesn't this work? It says: Can't find string terminator "EndHTML" anywhere before EOF

Replies are listed 'Best First'.
Re: String terminator problems.
by petdance (Parson) on Jun 21, 2001 at 05:30 UTC
    Two things:

    1) If you don't have a \n at the end of EndHTML, then it's not really there. I'm betting the last line of your file is just EndHTML^Z.

    2) You need a space after the colon in Content-type:. You may want to use CGI; and just call print header;.

    xoxo,
    Andy

    %_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
    'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
    "hack";print map delete$_{$_},split//,q<   andy@petdance.com   >
    
Re: hello
by voyager (Friar) on Jun 21, 2001 at 04:17 UTC
    Your code works for me, with or without the quotes around 'EndHTML'.

    I have heard that on Win32 you need a blank line after the marker for a "here documents" (although I'm on win32 and didn't need it).

    By the way, I first thougth it wasn't working until I noticed the title in the brower; you have nothing in the <body>.

(Daddio) Re: hello
by Daddio (Chaplain) on Jun 21, 2001 at 04:43 UTC

    The only time I have personally seen a message like that is when my terminator didn't start in column one. While this code does seem to have the terminator starting in column one, does the actual code you are running?

    The other thoughts I had are:

    • try without the single-quotes
    • try without the ending ; on the opening line

    I seem to have examples of code that have and don't have the bullet items above, and they all seem to work. That leads me back to the original positioning thought...

    D a d d i o

      Careful, that's not quite accurate!

      The single quotes force a non-interpolative context, just like single quotes around a string. By default, here documents act like double quoted strings. His construct is valid.

      Similarly, you can only get away without the semicolon in a place where a statement doesn't need a closing semicolon -- at the end of a block or the end of a file. In this case, it would work if the original poster posted his complete program.

      My guess is that adding a newline or something after the terminator would fix it. Perhaps his editor doesn't add an EOF? He could also use exit or __END__.

        Thanks, chromatic, for explaining those points a bit. I looked through code I have (both mine and others) and was completely unsure about (1) when to single/double quote and (2) use the semi-colon. I'm still learning, too, and thought I would point out that I have seen it done both ways (missing, of course, the reason why). Thanks again for clarifying.

        D a d d i o

Re: String terminator problems.
by Anonymous Monk on Jun 21, 2001 at 08:44 UTC
    all these monks here aren't as brilliant as me ;-)!
    when you say
    print <<' here is a here doc ';
    the here doc rules say that you need a line terminating with ' here is a here doc ' without the quotes and you obviously don't have one. a space after the heredoc also helps here is a here doc
Re: String terminator problems.
by timbo (Initiate) on Jun 21, 2001 at 16:28 UTC
    #!/usr/bin/perl -w use CGI qw(:all); print header, start_html("m o n k t a s t i c"); print "i'm a page"; print end_html; exit;
    will send out a page :) hth t

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://90260]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found