[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

heredoc with variable interpolation breaks script

Oliver Heins

9/11/2006 9:14:00 AM


Running this script, I get the following error:

,----
| olli@athene:~/tmp$ ./test.rb
| ./test.rb:5:in `test': wrong number of arguments (ArgumentError)
| from ./test.rb:5
| olli@athene:~/tmp$ ruby --version
| ruby 1.8.4 (2005-12-24) [i486-linux]
`----

I'm using ruby on a Debian unstable system.

TIA,
olli

--
GnuPG-Key: http://www.sopos.org/pg...
GnuPG-Fingerprint: F27A BA8C 1CFB B905 65A8 2544 0F07 B675 9A00 D827
NP: Nothing
2 Answers

Logan Capaldo

9/11/2006 2:36:00 PM

0

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}.
>
> Running this script, I get the following error:
>
> ,----
> | olli@athene:~/tmp$ ./test.rb
> | ./test.rb:5:in `test': wrong number of arguments (ArgumentError)
> | from ./test.rb:5
> | olli@athene:~/tmp$ ruby --version
> | ruby 1.8.4 (2005-12-24) [i486-linux]
> `----
>
> I'm using ruby on a Debian unstable system.
>
> TIA,
> olli
>
> --
> GnuPG-Key: http://www.sopos.org/pg...
> GnuPG-Fingerprint: F27A BA8C 1CFB B905 65A8 2544 0F07 B675 9A00 D827
> NP: Nothing


Oliver Heins

9/11/2006 4:00:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> 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

--
GnuPG-Key: http://www.sopos.org/pg...
GnuPG-Fingerprint: F27A BA8C 1CFB B905 65A8 2544 0F07 B675 9A00 D827
NP: Nothing