From: Ken Bloom Date: 2009-03-19T00:37:30+09:00 Subject: Re: Interpolating $1, etc., from within a gsub block On Tue, 17 Mar 2009 14:52:08 -0500, Lloyd Zusman wrote: > Lloyd Zusman asfast.com> writes: > >> [ ... ] >> >> string.gsub!($fromre) { >> |x| >> $replcount += 1 >> $repl >> } >> >> > Well, I came up with the following, but I'm still wondering if there is > a more elegant way to do this: > > string.gsub!($fromre) { > |x| > $replcount += 1 > eval "$result = \"#{$to}\"" > $result > } I think you're going overboard with variables (and global variables in particular) an eval "\"#{$to}\"" would have been sufficient here, and if you really needed a new variable, then calling it simply result (without the dollar sign) would have given you a local variable. -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/