7stud -- wrote: > > But that is poorly written code; I can see that you copied it off the OT > website. Instead, you can write something like this: > > results = [] > > File.open("data.txt") do |file| > file.each_line(',') do |field| > results << field.to_i > end > end > > p results > -->[10, 20, 30, 50, 60] > Whoops. That doesn't work because the end of a line is not a comma so the last field on a line is combined into a string with the first field on the next line, which mucks up the results. You could do something like this instead: results = [] File.open("data.txt") do |file| file.each_line() do |record| fields = record.split(",") fields.each do |field| results << field.to_i end end end p results -- Posted via http://www.ruby-forum.com/.