From: Mmcolli00 Mom Date: 2009-01-16T04:57:25+09:00 Subject: Re: undefined method `[]' for nil:NilClass - how to prevent? Brian Thanks!! Your code does exactly what I am needing it to do. Thanks for taking out the duplicates also. You are very skillful! This error occurred: I'll am looking to see if maybe I am missing a gem, not sure. >Value does not contain a match: Clashifting.rb:55: undefined method `+' for >nil:NilClass (NoMethodError) > from shifting.rb:143:in `each_with_index' > from shifting.rb:54:in `each' > from shifting.rb:54:in `each_with_index' > from shifting.rb:54 > from shifting.rb:53:in `each_line' > from shifting.rb:53 > from shifting.rb:52:in `open' > from shifting.rb:52 snippet of your code: File.open("temp.txt") do |src| src.each_line do |line| line.chomp.split(",").each_with_index do |word, i| counts[word][i] += 1 #line 55 end end end counts.each do |word, cols| if cols.uniq.size != 1 puts "Word #{word.inspect} occurs different times: #{cols.inspect}" end end -- Posted via http://www.ruby-forum.com/.