Trailing \ in %q[\a\b\c\] not treated as literal???

R

Richard Lionheart

Hi,

I ran the following on a WinXP/SP2 machine:

F:\>ruby --version
ruby 1.8.2 (2004-12-25) [i386-mswin32]

F:\>ruby -e "puts %q[\a\b\c]"
\a\b\c

F:\>ruby -e "puts %q[\a\b\c\]"
-e:1: unterminated string meets end of file

F:\>

It seems to me the last \ shouldn't need to be escaped as \\, though that
does work. What's up?
 
M

Mark Hubbart

T24gMTEvMTkvMDUsIFJpY2hhcmQgTGlvbmhlYXJ0IDxOb09uZUBub3doZXJlLm5ldD4gd3JvdGU6
Cj4gSGksCj4KPiBJIHJhbiB0aGUgZm9sbG93aW5nIG9uIGEgV2luWFAvU1AyIG1hY2hpbmU6Cj4K
PiBGOlw+cnVieSAtLXZlcnNpb24KPiBydWJ5IDEuOC4yICgyMDA0LTEyLTI1KSBbaTM4Ni1tc3dp
bjMyXQo+Cj4gRjpcPnJ1YnkgLWUgInB1dHMgJXFbXGFcYlxjXSIKPiBcYVxiXGMKPgo+IEY6XD5y
dWJ5IC1lICJwdXRzICVxW1xhXGJcY1xdIgo+IC1lOjE6IHVudGVybWluYXRlZCBzdHJpbmcgbWVl
dHMgZW5kIG9mIGZpbGUKPgo+IEY6XD4KPgo+IEl0IHNlZW1zIHRvIG1lIHRoZSBsYXN0IFwgc2hv
dWxkbid0IG5lZWQgdG8gYmUgZXNjYXBlZCBhcyBcXCwgdGhvdWdoIHRoYXQKPiBkb2VzIHdvcmsu
ICBXaGF0J3MgdXA/CgolcVtmb29dIGlzIGVxdWl2YWxlbnQgdG8gdGhlIHNpbmdsZS1xdW90ZWQg
c3RyaW5nIGxpdGVyYWwgJ2ZvbycuIEluCnRoZSBzYW1lIHdheSwgdGhlIG9ubHkgZXNjYXBhYmxl
IGNoYXJhY3RlcnMgYXJlIGJhY2tzbGFzaCBhbmQgdGhlCmNoYXJhY3RlciB0aGF0IGVuZHMgdGhl
IGxpdGVyYWw6CgonTWFya1wncyBzdHJpbmcnCiVxW3NxdWFyZSAoXF0pIGJyYWNrZXRdCgpBIGxp
dGVyYWwgYmFja3NsYXNoIGluIGEgc2luZ2xlIHF1b3RlZCBzdHJpbmcgb25seSBuZWVkcyB0byBi
ZSBlc2NhcGVkCndoZXJlIGl0IG1pZ2h0IGJlIGNvbmZ1c2VkIGFzIGVzY2FwaW5nIHRoZSBmaW5h
bCBxdW90aW5nIGNoYXJhY3RlciwKbGlrZSBpbiB5b3VyIGV4YW1wbGUuCgpIVEgsCk1hcmsK
 
K

Kevin Olbrich

In a quoted string, a \cx is an escape for ctrl-x, so the \c\] is
interpreted as ctrl-] as the \] is an escape for the bracket in the quoted
string. Since there is no close bracket you get an error.

Try this...

puts %q[\a\b\\c\\]

And you get

\a\b\c\

_Kevin

-----Original Message-----
From: Richard Lionheart [mailto:[email protected]]
Sent: Saturday, November 19, 2005 07:47 PM
To: ruby-talk ML
Subject: Trailing \ in %q[\a\b\c\] not treated as literal???

Hi,

I ran the following on a WinXP/SP2 machine:

F:\>ruby --version
ruby 1.8.2 (2004-12-25) [i386-mswin32]

F:\>ruby -e "puts %q[\a\b\c]"
\a\b\c

F:\>ruby -e "puts %q[\a\b\c\]"
-e:1: unterminated string meets end of file

F:\>

It seems to me the last \ shouldn't need to be escaped as \\, though that
does work. What's up?
 
R

Richard Lionheart

Thanks. I forgot about viewing %q?....? as a generalized single-quoted
string, as one of you said, and as Fulton said in "The Ruby Way". Thanks,
guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top