David Alan Black wrote:
> Simon Strandgaard <neoneye / adslhome.dk> writes:
> 
> > I think I read somewhere that perl6 uses $ in the regexp replacement string,
> > in order to avoid our escaping hell.  I think this is a good initiative.
> > So escape can be used freely:
> >   "hello".gsub!(/h/, %q|\'|)       #->  \'ello
> >   "hello".gsub!(/(.)$1/, '$&$1')   #->  helllo
> > 
> > Maybe we should do an RCR..  use dollar in regexp?
> 
> Hmmm... I thought Ruby was moving more in the direction of getting rid
> of Perl-like global variables :-) But anyway, I think the thing you're
> describing might lead to some awkward things.  I think it's more logical
> to treat $1 as just a regular variable for purposes of compiling the
> regular expression:
> 
>   /(def)/.match("abcdef")
>   puts $1                                 # def
>   /ABC#{$1.upcase}/.match("whatever")
> 
> If your change were made, $1 would be nil in the last line because
> there are no captures.  
> 
> And here, you'd get a kind of postponed compilation of re:
> 
>   /(abc)/.match("abc")
>   re = /(blah)#{$1}def/
> 
> Sorry for the dumb examples... but I think the problems would be real.

At first sight I wondered what you are talking about.  
I have never done any perl programming in my life. 
IIUC perl interpolates $ inside strings.. that gave me a clue to
what you are talking about.

Ruby should of cause not interpolate global variables!  :-)

--
Simon Strandgaard