From: Carlos Date: 2002-07-20T07:26:16+09:00 Subject: Re: newbie Q: parsing CSV file into 2D array > [...] > I'm trying to read in a series of records in a CSV file. Each record > has a number of fields. I then want to write out the records in a > paragraph form, if you will. This requires that I create a 2D array. > [...] Hi. Why do you need a 2d array? Do you need to refer to a previous row or anything like that? If not, I think that processing every line and then throwing it would be the best... Ok, here are some random thoughts about your problem... First, you can use a hash to store the values up to rpm_max, so you don't have to remember array positions. You can use the first line to extract the labels: fh = File.open("your_file.csv", "r") out = File.open("your_output", "w") labels = (fh.gets.chomp.split ',')[0..9] # now you read the values fh.each { |line| ary = line.chomp.split ',' # the first ten go to a hash values = {} ary.slice!(0..9).each_with_index { |v, i| values[labels[i]] = v } # with the rest we form temp/power pairs... maybe # in another hash? # first we can transform the strings into numbers, so # it would be easier to sort the temps later ary.map! { |v| v.to_i } # and later we fill the hash temps = Hash[*ary] # print anything using values and temps... } fh.close; out.close Hope this helps. Hope this compiles, too...