Hi --

On Sat, 29 Jul 2006, Jack Christensen wrote:

> Is there some reason heredocs fail if there is white space after the closing 
> string? Until I realized what was happening this caused me a good bit of 
> trouble. Invisible characters shouldn't cause stuff to fail.
>
> Example:
> s = <<-HEREDOC
> bla bla bla
> HEREDOC 
> This fails with:
>
> heredoc.rb:3: can't find string "HEREDOC" anywhere before EOF
> heredoc.rb:1: parse error, unexpected $, expecting tSTRING_CONTENT or 
> tSTRING_DB
> EG or tSTRING_DVAR or tSTRING_END
>
> Delete the spaces at the end of the 3rd line and it works.
>
> I looked through the relevant PickAxe sections and didn't find anything.

The thing is, the mechanism depends on an exact match.  Here's an
unlikely but possible example of why it might matter.  Line 10 is
"EOM"; line 12 is "EOM ".

irb(main):008:0> a,b = <<EOM, <<"EOM "
irb(main):009:0" abc
irb(main):010:0" EOM
irb(main):011:0" def
irb(main):012:0" EOM 
=> ["abc\n", "def\n"]


David

-- 
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
   ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com        => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black     => book, Ruby for Rails
http://www.rubycentral.org       => Ruby Central, Inc.