The beauty of CSV

So I'm working on a site right now that will be powered by Perl on the back and d3.js on the front.

And here's what I'm loving about d3, I can feed it CSV files. Yup. Not JSON. Not XML. Good old CSV.

I know, it's a bit primitive. And there's a good chance at some point I end up JSONing everything up. But I love me some CSV. And there are 551 CPAN packages for pushing, pulling, parsing, encoding or otherwise mangling it.

7 Comments

So, you prefer working with data that has no context or structure. Got it. :)

Sometimes data don't need context or structure. No point in adding overhead by using an inappropriate tool for the job at hand. CSV is great. Except when it isn't.

The context would be the request: "I requested ." The structure is rows and columns, lots of data is structured in rows and columns.

Could you give us some context here? Is it cool to diss CSV these days?

This is very interesting idea, thank you!

When I work with CSV I always meet the same problem. There is no strict standard for CSV and CSV stadard differ a lot.

Sometimes there is "\n" for new lines and sometimes there is "\r\n", sometime the values are in quotes, and timetimes there are without quotes, sometimes there are singe quotes and sometimes there are double quotes, sometimes the separator is comma and sometimes the separator is semicolon. And there is no information about encoding the CSV data should use.

To work with CSV I need to find you what kind of CSV it is and only then parse it.

How do you solve this problem?

The beauty of CSV is that you can edit in Excel. This can be a highly efficient way of creating and maintaining large tables of data when the data must be manually maintained. Far more efficient than editing YAML or JSON in a text editor.

See Config::Any::CSV - you can use this module to read CSV with Config::Any and later switch to another format (JSON, YAML...) without having to change your code.

Leave a comment

About Daniel Lathrop

user-pic Investigative reporter and web developer. These are my adventures in Perl.