From: "David A. Black" Date: 2008-06-19T04:58:59+09:00 Subject: Re: parsing text into usablle numerical data Hi -- On Thu, 19 Jun 2008, Cthulhu __ wrote: > Sot he code as taken from Chris' post returns this error: > > read_data.rb:72:in `[]=': no implicit conversion from nil to integer > (TypeError) > from read_data.rb:72 > from read_data.rb:69:in `foreach' > from read_data.rb:69 > > The code looks like this with line numbers... > > 69 File.foreach files_to_parse[i].to_s do |line| > 70 next if line.strip == '' > 71 idx, *dat = line.scan(/\d+/).map {|s| s.to_i} > 72 raw_data[idx] = dat > 73 end > 74 puts raw_data > > I suspect it may be a problem in the formatting of the data... perhaps > there is some way to remove any non-integer characters eg. delimiting > chars before parsing? The scan(/\d+/) will scan for digits, and will ignore everything else, so you don't have to pre-treat the lines. I would throw in: puts line if idx.nil? before line 72, and see which lines are giving you the problems. All the lines you showed in your sample data were either blank or contained only digits, so they shouldn't cause this problem. David -- Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS June 16-19 Berlin ADVANCING WITH RAILS July 21-24 Edison, NJ See http://www.rubypal.com for details and updates!