Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Here Documents" don't work?

Status
Not open for further replies.

Meiguoren

Technical User
Jun 16, 2008
4
Hello everyone,

I'm learning Perl via Mike Gossland's tutorial at The tutorial presents "here documents," apparently a holdover from UNIX that offers equivalent functionality to the explicit quoting operator, qq{}. Mike gives a nice example of how the operator works:

Code:
print <<EOF;
Content-Type: text/html

<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
<H4>Hello World</H4>
<P>
Your IP Address is $ENV{REMOTE_ADDR}
<P>
<H5>Have a "nice" day</H5>
<p>Name:<input type="text" size="20" name="txt_name" value="name">
</BODY>
</HTML>
EOF

The problem: it doesn't work! I'm using the most recent version of Perl 5, and I always get an error like "can't find string terminator 'EOF' anywhere before EOF at line 1."

My only guess is that support for here documents has been deprecated. Any suggestions? Thanks!
 
You need to make sure EOF is the very first thing on the line.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Oh yeah.. make sure you hit enter after the EOF .

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks for the help!

The problem was the lack of a newline after the "EOF", as you suggested. Why is it necessary?
 
Evidently it is the terminator for a here doc.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top