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

Discussion in 'Ruby' started by Richard Lionheart, Nov 20, 2005.

  1. 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?

    --
    TIA,
    Richard
     
    Richard Lionheart, Nov 20, 2005
    #1
    1. Advertising

  2. Richard Lionheart

    Mark Hubbart Guest

    T24gMTEvMTkvMDUsIFJpY2hhcmQgTGlvbmhlYXJ0IDxOb09uZUBub3doZXJlLm5ldD4gd3JvdGU6
    Cj4gSGksCj4KPiBJIHJhbiB0aGUgZm9sbG93aW5nIG9uIGEgV2luWFAvU1AyIG1hY2hpbmU6Cj4K
    PiBGOlw+cnVieSAtLXZlcnNpb24KPiBydWJ5IDEuOC4yICgyMDA0LTEyLTI1KSBbaTM4Ni1tc3dp
    bjMyXQo+Cj4gRjpcPnJ1YnkgLWUgInB1dHMgJXFbXGFcYlxjXSIKPiBcYVxiXGMKPgo+IEY6XD5y
    dWJ5IC1lICJwdXRzICVxW1xhXGJcY1xdIgo+IC1lOjE6IHVudGVybWluYXRlZCBzdHJpbmcgbWVl
    dHMgZW5kIG9mIGZpbGUKPgo+IEY6XD4KPgo+IEl0IHNlZW1zIHRvIG1lIHRoZSBsYXN0IFwgc2hv
    dWxkbid0IG5lZWQgdG8gYmUgZXNjYXBlZCBhcyBcXCwgdGhvdWdoIHRoYXQKPiBkb2VzIHdvcmsu
    ICBXaGF0J3MgdXA/CgolcVtmb29dIGlzIGVxdWl2YWxlbnQgdG8gdGhlIHNpbmdsZS1xdW90ZWQg
    c3RyaW5nIGxpdGVyYWwgJ2ZvbycuIEluCnRoZSBzYW1lIHdheSwgdGhlIG9ubHkgZXNjYXBhYmxl
    IGNoYXJhY3RlcnMgYXJlIGJhY2tzbGFzaCBhbmQgdGhlCmNoYXJhY3RlciB0aGF0IGVuZHMgdGhl
    IGxpdGVyYWw6CgonTWFya1wncyBzdHJpbmcnCiVxW3NxdWFyZSAoXF0pIGJyYWNrZXRdCgpBIGxp
    dGVyYWwgYmFja3NsYXNoIGluIGEgc2luZ2xlIHF1b3RlZCBzdHJpbmcgb25seSBuZWVkcyB0byBi
    ZSBlc2NhcGVkCndoZXJlIGl0IG1pZ2h0IGJlIGNvbmZ1c2VkIGFzIGVzY2FwaW5nIHRoZSBmaW5h
    bCBxdW90aW5nIGNoYXJhY3RlciwKbGlrZSBpbiB5b3VyIGV4YW1wbGUuCgpIVEgsCk1hcmsK
     
    Mark Hubbart, Nov 20, 2005
    #2
    1. Advertising

  3. 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:]
    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?

    --
    TIA,
    Richard
     
    Kevin Olbrich, Nov 20, 2005
    #3
  4. 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.
    --
    Richard
     
    Richard Lionheart, Nov 20, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Heavey
    Replies:
    1
    Views:
    392
    Oisín Grehan
    Dec 2, 2003
  2. Dmitriy Zakharov
    Replies:
    2
    Views:
    452
    Dmitriy Zakharov
    Jul 30, 2004
  3. Scott J. McCaughrin

    static data-member treated as extern

    Scott J. McCaughrin, Nov 8, 2004, in forum: C++
    Replies:
    2
    Views:
    499
    John Harrison
    Nov 9, 2004
  4. Eugene
    Replies:
    6
    Views:
    806
    Ken Cox [Microsoft MVP]
    Nov 11, 2004
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    413
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page