From: Josh Cheek Date: 2013-05-29T23:13:13+09:00 Subject: Re: AAARRRRGH! s="#$" => SyntaxError: compile error --001a11c25f4ea3215a04dddbe080 Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 28, 2013 at 5:31 PM, Tadeusz Bochan wrote: > Hi. > I get the following error from the following statement : > s="#$" > > irb(main):001:0> s="#$" > SyntaxError: (irb):1: unterminated string meets end of file > from C:/Ruby200/bin/irb:12:in `
' > (A similar response from 1.8.6 on HPUX.) > > Also, > > irb(main):011:0> s="#$!" > => "" > > Something is broken. Does anyone know whats going on with this ? > > As stated, #$... in a String will interpolate the $... In your case, there is a global variable `$"` which it is trying to interpolate, so you think you're ending the string, but really, that second quotation is part of the variable name (I assume this was all inherited from Perl). You would need to do "#$"" For whatever reason, this doesn't work in irb, but it does work in a Ruby program: ruby -e 'p "#$""' Anyway, to get around this, escape the hash so that it isn't looked at as interpolating: ruby -e 'p "\#$"' > Also, this is not good > irb(main):008:0> s=("xxxxxx.....#$yyyyyyyyy") > => "xxxxxx....." > > Again, just escape the hash s= "xxxxxx.....\#$yyyyyyyyy" > Is there a fundamental problem with the Ruby parser ? > or is this just an isolated glitch ? > > No, it's just unintuitive. On Wed, May 29, 2013 at 4:52 AM, Tadeusz Bochan wrote: > Thank you for all the replies. > > I didn't know about the interpolation without {}. > > The way I first saw the problem was : > I have a program (non-ruby) which dumps items out of a database in a > format which is compatible with "inspect". > > So, to read this, I was using "eval". > eg., text='"ABC\267#$"' > data=eval(text) > > It just so happened that one of the data items contained "#$". > > My workaround for the moment is : data=eval(text.gsub("#",'\\043')) > Any better suggestions ? > > I don't understand this, why do you want to eval "ABC\267\#$"? It is not valid Ruby (ignoring the nonsenical characters, it would mean 'look up the constant ABC', which is presumably not what you're intending). Can you give examples of inputs and outputs? --001a11c25f4ea3215a04dddbe080 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, May 28, 2013 at 5:31 PM, Tadeusz= Bochan <lists@ruby-forum.com> wrote:
Hi.
I get the following error from the following statement :
s=3D"#$"

irb(main):001:0> s=3D"#$"
SyntaxError: (irb):1: unterminated string meets end of file
=A0 =A0 =A0 =A0 from C:/Ruby200/bin/irb:12:in `<main>'
(A similar response from 1.8.6 on HPUX.)

Also,

irb(main):011:0> s=3D"#$!"
=3D> ""

Something is broken. Does anyone know whats going on with this ?


As stated, #$... in a String will= interpolate the $... In your case, there is a global variable `$"` wh= ich it is trying to interpolate, so you think you're ending the string,= but really, that second quotation is part of the variable name (I assume t= his was all inherited from Perl). You would need to do "#$""= For whatever reason, this doesn't work in irb, but it does work in a R= uby program:=A0ruby -e 'p "#$""'

Anyway, to get around this, escape the hash so that it = isn't looked at as interpolating:=A0ruby -e 'p "\#$"'=



Also, this is not good
irb(main):008:0> s=3D("xxxxxx.....#$yyyyyyyyy")
=3D> "xxxxxx....."


Again, just escape the hash
= s=3D "xxxxxx.....\#$yyyyyyyyy"
=A0
Is there a fundamental problem with the Ruby parser ?
or is this just an isolated glitch ?


No, it's just unintuitive.

<= div>On Wed, May 29, 2013 at 4:52 AM, Tadeusz Bochan=A0<= ;lists@ruby-forum= .com>=A0wrote:
Thank you for all the replies.<= br>
I didn't know about the interpolation without {}.

The way I = first saw the problem was :
I have a program (non-ruby) which dumps item= s out of a database in a
format which is compatible with "inspect&q= uot;.

So, to read this, I was using "eval".
eg., text=3D'&qu= ot;ABC\267#$"'
=A0 =A0 =A0data=3Deval(text)

It just so h= appened that one of the data items contained "#$".

My work= around for the moment is : data=3Deval(text.gsub("#",'\\043&#= 39;))
Any better suggestions ?


I don't understand this, why = do you want to eval "ABC\267\#$"? It is not valid Ruby (ignoring = the nonsenical characters, it would mean 'look up the constant ABC'= , which is presumably not what you're intending). Can you give examples= of inputs and outputs?

--001a11c25f4ea3215a04dddbe080--