From: Brian Candler Date: 2010-09-27T17:30:10+09:00 Subject: Re: bug in gsub(?) Chad Perrin wrote: > I wouldn't really call \1 a "Perlism", given that the way I've always > seen it done is with $1 instead. I called \1 a perlism mainly because it's a sedism that perl inherited. You're right that in Perl you could instead write: $str =~ s/(.)/$1$1/; Of course, that doesn't work in Ruby without using the block form: str.sub(/(.)/, "$1$1") # no! str.sub(/(.)/, "#{$1}#{$1}") # no!! str.sub(/(.)/) {"#{$1}#{$1}"} # ok in which case you could either argue that ruby needs sed's \1 more than perl does, or you could argue that ruby doesn't need it at all. It's odd that ruby strives to be so perl-compatible in areas like this, but is different in far more important areas (e.g. ^ matching newlines within a string, not just the start of string) Regards, Brian. -- Posted via http://www.ruby-forum.com/.