OT: CSV flavors

J

Jeff Thies

I'm writing a little utility to insert/edit CSV files as standard
HTML tables.

I understand that some CSV files do \" instead of "" to deal with double
quotes. What exports CSV that way? I haven't seen it.

I'm trying to figure if I really need to deal with \"!

Jeff
 
T

Toby Inkster

Jeff said:
I understand that some CSV files do \" instead of "" to deal with double
quotes. What exports CSV that way? I haven't seen it.

I can imagine that many CSV files exported from SQL databases would do.

Have you considered CSV files with no escaping for double-quotes at all?

My solution is to use *tab*-delimited files and ban the use of tabs and
new lines as part of the data. Dead easy to parse then:

#!/usr/bin/perl
$_ = `cat data`;
@_ = split(/\n/);
print "<table>\n";
while ($_ = shift) {
@a = split(/\t/);
print '<tr><td>' . join('</td><td>',@a) . "</td></tr>\n";
}
print "</table>\n";
 
J

Jeff Thies

Toby said:
Jeff Thies wrote:




I can imagine that many CSV files exported from SQL databases would do.

OK. I'll bear that in mind.
Have you considered CSV files with no escaping for double-quotes at all?

You mean no "" or no \"?
My solution is to use *tab*-delimited files and ban the use of tabs and
new lines as part of the data. Dead easy to parse then:

#!/usr/bin/perl
$_ = `cat data`;
@_ = split(/\n/);
print "<table>\n";
while ($_ = shift) {
@a = split(/\t/);
print '<tr><td>' . join('</td><td>',@a) . "</td></tr>\n";
}
print "</table>\n";

I like tab delimited. Nobody uses tabs in data, but they do use line
feeds. Then you have to count quotes and glue the lines back together.

Thanks!
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top