O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CSV

In Chapter 5, Delimited Data, we looked at reading from CSV files, a common need when it comes to acquiring text for your program. But it’s often necessary to write CSV files, too.

We can do this using the same CSV library that we used to read the files. It has a capable interface for generating CSV data, writing directly to files, and modifying existing CSVs.

There are generally two reasons we’d want to write a CSV file. The first is when we want to take a data structure from our Ruby code and write it out to a CSV. The second is when we want to take an existing CSV file and modify it. These two different tasks have two different approaches. Let’s take a look at them in turn.

Serializing Existing Data

If we’re generating the data that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required