On 12/7/07, Jon H. [email protected] wrote:
different depending on which line I’m looking at. Here’s some psuedo
The problem is that this is not a line-oriented set of data. So I have
to have some kind of nested loop that advances the line counter. Or,
there has to be some record-oriented I/O that lets me process the file
as a set of records. Surely there’s some cool, ruby way to do this?!??
I see - i misunderstood your question.
I don’t know about cool & rubyish, but I’d skip the each and do
something like this:
dataset={}
File.open(“myfile.txt”, ‘r’) do |f|
while (!f.eof)
name = f.gets.chomp
data=[]
f.gets.to_i.times {
data << f.gets.chomp.split(",")
}
dataset[name] = data
end
end
p dataset
That assumes that record is comma separated and can be stored as a
simple array. For a more complicated record, use something like
data << MyRecord.new(f.gets.chomp)
Hope this helps,
-Adam