Parsing text data into an array

using ruby I/O to convert structured text into usable numberical data

Page 1 of 1

0 Replies - 3906 Views - Last Post: 17 June 2008 - 10:37 AM Rate Topic: -----

#1 cthulhu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-June 08

Parsing text data into an array

Post icon  Posted 17 June 2008 - 10:37 AM

Hey total ruby n00b here...
I'm having trouble with parsing data into ruby for statistical analysis.

The data looks like this:
32 0 0 0 0 0 0 0 0 8412803500 0 0 0 0 0 0 0 46655166 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 240554000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 85321000 0 0 0 0 0 0 0 479719000 0 0 0 97823285 283432000 0 73887750 0 0 157225000 88659750 285211000 70285000 0 161747000 161167000 234739666 120400000 300083000 0 0 202327250 111865000 183127000 0 161027000 0 0 0

33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

I need to store the index of the entry, in this case 32 and 33, as the name of the 2 Dimensional array (array of arrays as ruby handles it?) and then each value (alot of zeros in the case of 33) as a unique entry. The format is plain tyext right now and I have had no luck using File.readline

For some reason this does NOT work, the array dimensions do not match expected structure:
elsif /aqua_t/=~(files_to_parse[i])
line_counter = 0
line = File.readlines(files_to_parse[i]).each do |line|
line.each{|x| x.to_i}
raw_data_t[line_counter]=line.split
aqua = [0]
line_counter+=1
end#ends block over lines


Any advice would be much appreciated.
--m

Is This A Good Question/Topic? 0
  • +

Page 1 of 1