# Heredoc with variable interpolation breaks script

**URL:** <https://www.ruby-forum.com/t/heredoc-with-variable-interpolation-breaks-script/68272>\
**Category:** Ruby\
**Created:** [September 11, 2006, 11:21am UTC](https://www.ruby-forum.com/t/heredoc-with-variable-interpolation-breaks-script/68272 "2006-09-11T11:21:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oliver\_Heins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b487fb/32.png) [@Oliver\_Heins](https://www.ruby-forum.com/u/Oliver_Heins)\
**Post date:** [September 11, 2006, 11:21am UTC](https://www.ruby-forum.com/t/heredoc-with-variable-interpolation-breaks-script/68272/1 "2006-09-11T11:21:46Z")

</div>

#!/usr/bin/ruby

var1 = “test”  
var2 = \<\<EOF  
let us look #{test}  
EOF  
puts var2

---

<div class="post-metadata">

**Author:** ![Oliver\_Heins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b487fb/32.png) [@Oliver\_Heins](https://www.ruby-forum.com/u/Oliver_Heins)\
**Post date:** [September 11, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/heredoc-with-variable-interpolation-breaks-script/68272/2 "2006-09-11T16:36:25Z")

</div>

On Mon, Sep 11, 2006 at 06:20:34PM +0900, Oliver Heins wrote:

> I have a somewhat weird problem: Since a few days (I recognized  
> yesterday) a script ceased to work which did perfectly before. I  
> stripped it down to a heredoc with string interpolation, which now  
> breaks the script. Here’s a minimal example:

> #!/usr/bin/ruby
> 
> var1 = “test”  
> var2 = \<\<EOF  
> let us look #{test}  
> EOF  
> puts var2  
> You are calling the method “test” (which is a perlism, FYI) inside your  
> HEREDOC. I’m pretty sure this was just a typo, and you meant to say  
> #{var1}, not #{test}.

---

<div class="post-metadata">

**Author:** ![Oliver\_Heins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/b487fb/32.png) [@Oliver\_Heins](https://www.ruby-forum.com/u/Oliver_Heins)\
**Post date:** [September 11, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/heredoc-with-variable-interpolation-breaks-script/68272/3 "2006-09-11T18:06:38Z")

</div>

Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> You are calling the method “test” (which is a perlism, FYI) inside your  
> HEREDOC. I’m pretty sure this was just a typo, and you meant to say  
> #{var1}, not #{test}.

Indeed, it was a typo. The real error was that I did a chomp on an  
undefined array-entry. I create the array key on the fly and was just  
presuming that the source I was parsing contained the specific entry.  
As the source changed, my script failed. I now initialize the array  
keys with an empty string and everything works fine.

Thanks for the hint.  
olli
