Read_with_new.rb

This content was produced by an LLM and could include errors.

This script opens and processes a CSV file, treating the first row as headers. It then iterates through each subsequent record, printing every associated key-value pair found.

require 'csv'
#=> true

File.open("input/csv/file.csv", "r") do |f|
  csv = CSV.new(f, headers: true)
  csv.each do |line|
    line.each do |header, val|
      p [header, val]
    end
    puts
  end
end
["key", "key1"]
["value", "value1"]

["key", "key2"]
["value", "value2"]

["key", "key3"]
["value", "value3"]

#=> nil

Ruby 4.0.3