# Syntaxerror with HERE document

**URL:** <https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726>\
**Category:** Ruby\
**Created:** [September 4, 2007, 11:52am UTC](https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726 "2007-09-04T11:52:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [September 4, 2007, 11:52am UTC](https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726/1 "2007-09-04T11:52:33Z")

</div>

Why does the following statement give syntax error “undefined method  
`STDOUT’”?

STDOUT \<\<-END  
line 1  
line 2  
END

After all, the following works:

s=\<\<-END  
line 1  
line 2  
END  
STDOUT \<\< s

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [September 4, 2007, 11:55am UTC](https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726/2 "2007-09-04T11:55:34Z")

</div>

Ronald F. wrote:

> Why does the following statement give syntax error “undefined method  
> `STDOUT’”?
> 
> STDOUT \<\<-END  
> line 1  
> line 2  
> END

Because that’s equivalent to STDOUT “bla”, not STDOUT \<\< “bla”.  
The \<\< in your code is part of the heredoc syntax. You want  
STDOUT \<\< \<\<-END  
line 1  
line 2  
END

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [September 4, 2007, 12:03pm UTC](https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726/3 "2007-09-04T12:03:35Z")

</div>

Ronald F. wrote:

> Why does the following statement give syntax error “undefined method  
> `STDOUT’”?
> 
> STDOUT \<\<-END  
> line 1  
> line 2  
> END

this means:  
tmp\_str=“line 1\nline 2\n”;  
STDOUT tmp\_str;

> After all, the following works:
> 
> s=\<\<-END  
> line 1  
> line 2  
> END  
> STDOUT \<\< s

and this means:  
tmp\_str=“line 1\nline 2\n”;  
STDOUT\<\<tmp\_str;

STDOUT is a var(the std out)  
“\<\<” is a _method_ of STDOUT

–  
[http://kdr2.net](http://kdr2.net)

```
                                            ------yours Killy Draw

```

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [September 4, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/syntaxerror-with-here-document/113726/4 "2007-09-04T12:05:35Z")

</div>

> The \<\< in your code is part of the heredoc syntax. You want  
> STDOUT \<\< \<\<-END  
> line 1  
> line 2  
> END

Of course, that’s it!!! I must have been blind! Thanks a lot.

Ronald
