From: Alex Young Date: 2007-11-22T03:53:48+09:00 Subject: Re: False positives in editing data RichardOnRails wrote: > On Nov 19, 2:23 am, Ryan Davis wrote: >> Those evals are TERRIFYING. Don't use them. > > How else can you loop through $1, $2 ... without repetitive code? I don't think anyone has replied to this, so... This is what you've got: > sName =~ /^([\d]+)?\.?([\d]+)?\.?([\d]+)?\.?/ > > > # Save match variables in n[1] ... n[MLN+1] > n = Array.new > (1..MLN+1).each { |i| eval %{n[i] = $#{i}} } You can get an equivalent for n with the String#match method: irb(main):001:0> name = "2.2.02Topic 2.2.2" => "2.2.02Topic 2.2.2" irb(main):002:0> m = name.match( /^([\d]+)?\.?([\d]+)?\.?([\d]+)?\.?/ ) => # irb(main):003:0> m[1] => "2" irb(main):004:0> m[2] => "2" irb(main):005:0> m[3] => "02" You should be able to use that to get around your second eval, too. -- Alex