From: Moya Pilot Date: 2010-04-26T08:23:50+09:00 Subject: Re: When to use a db? Thank you all for your comments, I really appreciate it. I have to admit I am new to Ruby and fairly new to programming in any language and am still confused about a lot of things. To explain my needs a little better, I am reading in thousands of lines in a day via a tcp connection. Most lines will be one attribute updates to an object but the lines I am reading are like so NAME, jim joe, 123-456-7890, 123 elm st, zip PREFS, firefox, flash 10, java, windows, jim joe FAVORITES, facebook, jim joe, ebay, google In short, I am reading them in via fastercsv and working on using an if statement to do something to see if the username exists in the array already, if so update the object found with the needed data. If not add the new data to as a new object in the array. User = Struct.new(:a, b:, c:, d:, e:, f:, g:, h:, i:, j:, k:, l:, m:, n:, o:, p:, q:, r:) array=[] CSV.parse lines do |row| if ( lines =~ /^NAME:/) array.find{ |foobar| if foobar.b == row[1] puts "User already added" elsif ( lines =~ /^PREFS:/) array.find{ |foobar| if foobar.b == row[5] puts "This is where I need so other help, I need to add this rows contents[0..4] to the object matching in the array, so I think something like foobar[6, 7, 8, 9] = row[1, 2, 3, 4]" elsif ( lines =~ /^FAVORITES:/) array.find{ |foobar| if foobar.b == row[2] puts "This is where I need so other help, I need to add row[1, 3, 4] contents to the object matching in the array, so I think something like foobar[12, 14, 15] = row[1, 3, 4]" else array << User.new(*row[0..5]) end } I have been re-reading some more on hashes but I am still confused on the differences between hashes and arrays. If it is simply just giving a name to something like array[0] I am not sure how that speeds things up. I am also still confused on how to efficiently add the cvs parsed rows into an object in the array. Is array.find my best bet if using an array? Would hashes work or BDB, GDBM or SQLite be better suited towards this? Thanks again I appreciate all your help. -- Posted via http://www.ruby-forum.com/.