However, if I actually type the tabs, it doesn’t work:
require ‘csv’
str =<<“END_OF_STRING”;
cow pig
hello “hello world” world
END_OF_STRING
CSV.parse(DATA, :col_sep => “\t”) do |row|
p row
end
–output:–
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1895:in block (2 levels) in shift': Illegal quoting on line 1. (CSV::MalformedCSVError) from /Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1863:ineach’
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1863:in block in shift' from /Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1825:inloop’
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1825:in shift' from /Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1767:ineach’
from
/Users/me/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/csv.rb:1370:in parse' from ruby.rb:8:in’
The error you got is quite cryptic, but it makes sense: you had a
single column, which contained quotes not at the beginning or end -
CSV parser considers this incorrect.
– Matma R.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.