From: Francisco Martinez Date: 2010-07-10T08:44:47+09:00 Subject: Re: FIRST PROGRAMMING PROBLEM Array unknown wrote: > On Fri, Jul 9, 2010 at 2:01 PM, Francisco Martinez > wrote: >> it reads the wole text not considering each word or "." but reading each >> line...I need to put it in a method that calls "text.txt" and to use an >> array and the result must be each line one word. > > Assuming you had a method that printed each line of the file like: > > f=File.open(txtFile) > f.each do |line| > puts line > end > f.close > > On Fri, Jul 9, 2010 at 1:31 PM, Alex Stahl wrote: >> You can put individual elements into the array w/ the push operator >> "<<": myArray << "someTxt" > > (One way that) You could modify it to put each line in an array like: > > a = [] > f=File.open(txtFile) > f.each do |line| > a << line > end > f.close > > Of course, in your case you would want to extract the tokens from the > line and stick them in the array instead. Tank you very much...muy problem is that I don't know how to extract each token...because in this way I'm putting lines and I don't know how to print the tokens...I think I should use a regular expression... -- Posted via http://www.ruby-forum.com/.