From: Armin Roehrl Date: 2002-06-08T17:12:05+09:00 Subject: Re: Help: Improper use of gsub? Hi, > content2.gsub(//, fs) try calling gsub! instead of gsub as otherwise content2 does not get changed. irb(main):002:0> s.gsub(//, "foo") "foo" irb(main):003:0> s "" irb(main):004:0> s.gsub!(//, "foo") "foo" irb(main):005:0> s "foo" Hope this helps, Armin Am Samstag, 8. Juni 2002 08:06 schrieben Sie: > All- > > The code below correctly creates one copy of file "template.txt" for each > line in the file "packages.txt", and names each copy with the text in > field[0] in each line. > > For each copy, I am trying to replace the string "" with the > file object fs (a very short file). However, the "" string is > not bing replaced. Am I making incorrect use of the gsub method (in 2nd > line from bottom)? If so, please suggest a correction. > > content = File.new("template1.txt").read > fs = File.new("fiddle.sticks").read > IO.foreach("packages.txt") { |x| > field = x.chop.split(':') > content2 = content > content2.gsub(//, fs) > File.new(field[0],"w+").write(content2) > } > > Thanks. > > -Kurt Euler -- Armin. ----------------------------------------------- Armin Roehrl, http://www.approximity.com Training, Development and Mentoring OOP, XP, Java, Ruby, Smalltalk, Datamining, Parallel computing, Webservices Koautor des ersten dt. Rubybuches http://approximity.com/rubybuch/ Naechstes Rubyseminar: 9/9-11/9 in Hamburg. Don't work hard, work smart.