From: Bryan Weatherly Date: 2010-02-03T22:41:18+09:00 Subject: Re: Parsing text with while loop. --0016e6d7e345519583047eb25f32 Content-Type: text/plain; charset=ISO-8859-1 I edited your code and just changed a couple lines: http://pastie.org/807473 I changed this: input_file_stream = File.open(input_filename, "r") To this: input_file_stream = IO.readlines(input_filename) Using IO.readlines will just read the entire contents of the file and store each line as an element in an array. You can then iterate through the array rather than using a while loop. I changed your loop and changed the line where you split the lines of the csv file from this: input_file_line = input_file_stream.gets.to_s.split(/,/) To this: input_file_line = line.split(/,/) This should work, I obviously did not test it. Hopefully this will point you in the right direction. Bryan On Tue, Feb 2, 2010 at 12:51 PM, Felix Feelx wrote: > I am parsing a csv file and I am unable to end my loop as I want it. > > When I run my ruby file, I get this : > > feelx@tbiweb:~/public_html$ ruby csv_to_sql.rb > /usr/lib/ruby/1.8/date/format.rb:1055:in `dup': can't dup NilClass > (TypeError) > from /usr/lib/ruby/1.8/date/format.rb:1055:in `_parse' > from /usr/lib/ruby/1.8/date.rb:999:in `parse' > from csv_to_sql.rb:43 > > Link to my code : http://pastie.org/806415 > > Thanks in advance. > > Felix > -- > Posted via http://www.ruby-forum.com/. > > --0016e6d7e345519583047eb25f32--