Be a Supporter!

CGI easy question #1: here-document

  • 205 Views
  • 2 Replies
New Topic Respond to this Topic
DroopyA
DroopyA
  • Member since: Dec. 10, 2002
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
CGI easy question #1: here-document 2004-10-14 11:33:30 Reply

I'm confused... why doesn't this work?

#!/usr/bin/perl -wT
print "Content-type: text/html\n\n";
print <<EndOfHTML;
<html><head><title>Test Page</title></head>
<body>
<h2>Hello, world!</h2>
</body></html>
EndOfHTML

If I use multiple print lines instead of the <<EndOfHTML line it works but when I changed it to use the here-document syntax I get an Internal Server Error. I'm sure it's something easy, I just don't know what to look for... a semi colon somewhere maybe?


Request deletion
This went wrong.

DroopyA
DroopyA
  • Member since: Dec. 10, 2002
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to CGI easy question #1: here-document 2004-10-14 11:44:57 Reply

strange... I rewrote it but changed EndOfHTML to just EndHTML and now it works. Although, I still can't figure out why this works when the other one didn't. Their exactly the same.. arn't they?

#!/usr/bin/perl -wT
print "Content-type: text/html\n\n";
print <<EndHTML;
<html><head><title>Test Page</title></head>
<body>
<h2>Hello, World!</h2>
</body></html>
EndHTML


Request deletion
This went wrong.

DroopyA
DroopyA
  • Member since: Dec. 10, 2002
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to CGI easy question #1: here-document 2004-10-14 11:48:09 Reply

I figured it out finally...

"When a closing here-document marker is on the last line of the file, be sure you have a line break after the marker. If the end-of-file mark is on the same line as the here-doc marker, you'll get an error when you run your program."

Really, isn't this something they should tell you FIRST? Thanks for the help anyway... I'm sure I'll have more WTF's like this here shortly. :)


Request deletion
This went wrong.