J-H Johansen
8/28/2007 8:14:00 AM
On 8/28/07, Peter Marks <petertmarks@gmail.com> wrote:
> Follow up question:
>
> How might I be able to make multiple placeholders within a text file? I
> thought this would work:
>
> File.open("source.txt", "r") do |src|
> File.open("sink.txt", "w") do |sink|
> src.each_line { |line| sink.write(line.gsub(/placeholder/, "word"))
> sink.write(line.gsub(/placeholder2/,
> "word2"))
> }
> end
> end
>
> , but my newbie assumptions were mistaken. Any ideas?
Nearly there though ;-)
I think you can connect all the gsub's together for that effect.
File.open("source.txt", "r") do |src|
File.open("sink.txt", "w") do |sink|
src.each_line { |line|
sink.write(line.gsub(/placeholder/, "word").gsub(/placeholder2/,"word2"))
}
end
end
You could also create a Hash for placeholder => word in case you have
a lot of things that needs to be changed.
> Thanks,
>
> Peter
--
J-H Johansen
--
There are 10 kinds of people in the world: Those who understand binary and
those who don't...