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 `<main>'
(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 Tue, May 28, 2013 at 5:31 PM, Tadeusz Bochan <lists@ruby-forum.com>wrote:
On Wed, May 29, 2013 at 4:52 AM, Tadeusz Bochan <lists@ruby-forum.com> 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?