From: KUSUNOSE Toru Date: 2002-12-01T13:15:06+09:00 Subject: Re: Scope of regex match $variables Hi, In message <_qaG9.12613$Qr.238759@news3.calgary.shaw.ca>, Martin DeMello wrote: >Paul Melis wrote: >> "Martin DeMello" wrote in message >> news:NX3G9.135966$ka.3103955@news1.calgary.shaw.ca... >>> Yeah, but I can't figure out a way to make them local to the calling >>> scope, the way an actual Regexp#match call would. >> >> Why not simply return the MatchData object from your function? > >I do, but I thought it'd be nice to have the $n variables set as well. I >suppose one *shouldn't* be allowed to implicitly set variables in the >calling scope, though, now that I think about it. Those $n variables are derived from $~ , the local MatchData object. You can assign your MatchData object to it and get $n variables. The following code: def mymatch(a,b) a =~ b p $1 $~ end match = mymatch(/(e..)/,'hello') p $1 $~ = match p $1 prints "ell", nil, "ell". Hope this helps. -- KUSUNOSE Toru mailto:kusunose@hcn.zaq.ne.jp