Forum: Ruby Substituting from another file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tom H. (Guest)
on 2006-04-12 17:31
I have a textfile with a long text, and a wordlist with words both in
letters and phonetic notation. I want to substitute all the words in the
text with their phonetic spelling from the wordlist.

The wordlist entries look like this:
PANELED  P AE1 N AH0 L D
PANELING  P AE1 N AH0 L IH0 NG
etc.

What I have come up with so far:

f = File.open("textfile","r+")
d = File.open("dictionary")
g = File.open("outputfile","r+")
s = IO.read("textfile")
w = IO.read("dictionary")
s.gsub!(/.+? /) {|match| w.match($1)}
g.write(s)
f.close
d.close

This seems to enter an infinite loop.
This topic is locked and can not be replied to.