[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

FasterCSV question

Reid Thompson

11/6/2006 2:20:00 AM

Given a pipe '|' delimited file ala:
rthompso@jhereg:~$ cat pipedata
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to error|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|
A|This is text|Is this supposed to "error"|

and scripting ala:

rthompso@jhereg:~$ cat pipedata.rb
require 'rubygems'
require 'faster_csv'

FasterCSV.foreach("/home/rthompso/pipedata", :col_sep => '|') do |row|
# use row here...
next if row.empty?
puts row
end

Why are rows that contain quoted data deemed MalFormed?

1 Answer

James Gray

11/6/2006 3:35:00 AM

0

On Nov 5, 2006, at 8:19 PM, Reid Thompson wrote:

> A|This is text|Is this supposed to "error"|

This line is not a legal CSV format. To be correct it would need to be:

A|This is text|"Is this supposed to ""error"""|

Luckily, it's a trivial format you shouldn't need FasterCSV to
parse. You can break it down with:

fields = line.split("|")

Hope that helps.

James Edward Gray II