From: Peter Bailey Date: 2007-09-21T22:55:33+09:00 Subject: Re: Iterating through a file, sticking iterated array entrie Morton Goldberg wrote: > On Sep 20, 2007, at 11:41 AM, Peter Bailey wrote: > >> ... >> I'm getting the following. My "puts" statement, which is just there >> above code. Is gsub not an iteration tool? > The gsub! matches all the substitution targets on the first iteration > of the 'each'; therefore, no matches occur on any subsequent > iterations. Try something like: > > > source = < The quick brown > jumped over > the lazy > The quick brown > jumped over > the lazy > TEXT > > codes = %w[a b c d e f g] > source.gsub!(/<(\w*)>/) { c = codes.shift; "<#{c}>#{$1}"} > puts source > > > > The quick brown > fox jumped over > the lazy dog > The quick brown > fox jumped over > the lazy dog > > > Regards, Morton Thanks a lot, Morton. Yes, I've modified my approach. I just had to expand my mind to really consider how to contain each discrete thing that I want in these huge text files I'm getting. Once I've got them all in an array, I see now that I can do stuff to each entry in the array. Exactly what I need. Your suggestion helped. Thanks again. -- Posted via http://www.ruby-forum.com/.