On Jul 28, 2006, at 7:51 PM, Eric Armstrong wrote: > Logan Capaldo wrote: >> when I need to gsub backslashes I use a block: >> gsub(%r{\}) { '\\' } > That's odd. I would have expected that to work, > since the value of the block is the value of > the string. > > But %r{\} produces: > "unterminated string meets end of file" > > And { '\\' } inserts a single backslash. > > Paul's version worked: > gsub("\\"){ "\\\\" } > > As did this: > gsub(%r{\\}) { '\\\\' } > > Thanks for all the choices! I'm picking the > version with the simplest syntax I'm likely > to recall: > gsub("\\") { '\\\\' } > > It may be slower, but it's readable. > > Thanks again, guys. There is no way on earth > I would found the solution. Heck, even now > that I see it, I don't really understand it. > (I'm hoping that Paul's in-depth explanation > will make more sense after I've read it 5 or > 6 times.) > :_) > > Sorry, that wasn't meant to be a _real_ example. It was just the idea of throwing the block out there so you didn't have to deal with the very domain specific logic of gsub's second argument. > > > > >