From: Chris Hulan Date: 2008-06-19T04:03:47+09:00 Subject: Re: parsing text into usablle numerical data On Jun 18, 2:10 pm, Cthulhu __ wrote: > Still having some problems with this program. I'm getting a TypeError > when the value of > > dx, *dat = line.scan(/\d+/).map.compact > is nil > > Any suggestions on how to handle this? my current implementation looks > like this: > > raw_data = Array.new > File.foreach files_to_parse[i].to_s do |line| > idx, *dat = line.scan(/\d+/).map.compact! {|s| s.to_i} > raw_data[idx] = dat > end ... looks like the blank line between records is the culprit could just skip it explicitly: > File.foreach files_to_parse[i].to_s do |line| next if line.strip == '' #skip line if it is empty > idx, *dat = line.scan(/\d+/).map.compact! {|s| s.to_i} > raw_data[idx] = dat > end In response to your question re where idx comes from, the code in that line is creating an array of ints from the current line, then the parallel assignemnt is puting the first number in the array into idx, and putting the rest of the array into dat hth Chris cheers