title: Find out if CSV file contains empty field in Ruby?
body: <p>Using Ruby 1.9.3, I want to read in a CSV file with headers and scan each single field to see if it is left empty and does not contain a value, like <code>foo,,bar,foofoo,barbar</code>(the second one).</p>
  
  <p>My approach is as follows:</p>
  
  <pre><code>require 'CSV'
  
  #read csv file line by line
  CSV.foreach(filename,headers:true) do |row|
  
      #loop through each element within the current row
      for i in (0..row.length-1)
  
          #check for empty fields
          if !row[i]
              puts "empty field"
          end
       end
  end
  </code></pre>
  
  <p>Well, this works, but when processing a file with ~18 million fields, this is quite slow, and I have many of them. Is there any faster and more elegant ways to do this?</p>