From: Farrel Lifson Date: 2006-10-27T22:37:38+09:00 Subject: Re: reading variables in a file On 27/10/06, Ooo Grec wrote: > I'm thinking of migrating from Fortran to Ruby. Do you think i should go > ahead?? > First problem i have. > How to read a file with several fields? This means: > Imagine a file: > Peter4 1990 > Sam 3 1980 > Grac6 1991 > > I would like to read for each line:name, order and year (3 variables per > line). How can i do this? and how can i write them into a file?? > Thank you in advance. > > -------------------------------------------------------------------------------- > > -- > Posted via http://www.ruby-forum.com/. File.open(file) do |f| f.each_line do |line| name,order,year = *line.split end end Farrel