Code :

require 'csv'

content = <<CSV
id,first name,last name,age,sex
12,arup,rakshit,26,M
11,ayan,das,25,M
44,puja,roy,19,F
18,Dolly,Sen,21,F
CSV

File.write('a.csv',content)

CSV.foreach('a.csv') do |row|
  p row
end

**output**

# >> ["id", "first name", "last name", "age", "sex"]
# >> ["12", "arup", "rakshit", "26", "M"]
# >> ["11", "ayan", "das", "25", "M"]
# >> ["44", "puja", "roy", "19", "F"]
# >> ["18", "Dolly", "Sen", "21", "F"]

Till now perfect. But why the same is not happening with CSV::filter
(http://www.ruby-doc.org/stdlib-2.1.0/libdoc/csv/rdoc/CSV.html#method-c-filter)
method. I am not getting the rows, rather than name of the file twice.
What wrong I did ?

CSV.filter('a.csv',:col_sep => ",") do |csv|
  p csv
end

# >> ["a.csv"]
# >> a.csv

-- 
Posted via http://www.ruby-forum.com/.