From: Peter Bailey Date: 2006-04-07T01:06:44+09:00 Subject: Re: Basic input/output question Ilmari Heikkinen wrote: > Hi, > > On 4/6/06, Peter Bailey wrote: >> Hello, >> I spent my $40 on "Programming Ruby," but, it seems dedicated to C >> programmer rocket scientists. I work in publishing and basically I just >> need to open files, convert the data, and write the files, either to the >> same file or to another. Can someone please help me to write a simple >> structure to read a file "text1.txt", do regexes and stuff in it to >> convert data, and then write the output to "text2.txt." >> >> Thank you very much. >> > > If your files aren't very large, the simple way is to: > > data = File.read("text1.txt") > result_data = do_stuff_to( data ) > # open text2.txt in "w"rite mode > File.open("text2.txt", "w"){|text2| > text2.write(result_data) > } Thank you! This is great stuff, from all you guys. You're all heroes. . . . -- Posted via http://www.ruby-forum.com/.