From: Luc Traonmilin Date: 2009-03-14T02:23:48+09:00 Subject: Re: reading data files with headers and columns Yaj Bhattacharya a �crit : > Hello, > > As a noob to Ruby, I need to read a data file with the first few lines > as header, then the rest of the file as columns of different variables > as arrays (in this case, 5 columns). > After reading in the variables, I want to calculate some operations > with each unique data field address (e.g. column3, row4), then write > out the file with headers and data in columns. > > Could someone help with a few lines of basic code? > > Thanks in advance > Yaj > > > You could start with this basic piece of code (replace with your code): # here's the columns as arrays @column1 = [] # open file in read mode (r) file = File.new("") # assign variable to column @column1 << array[0] # ... process other columns end Additionnally you can google "ruby array" and "ruby file", the API docs are well documented. Luc