On 8/23/06, Peter Bailey <pbailey / bna.com> wrote:
> Hi,
> I have spreadsheet-like data, a table of data really, that I need to be
> able to access on a row-by-row, column-by-column, even cell-by-cell
> basis. I need to look at incoming filenames in a directory and match
> those filenames with the leftmost column of this table. Then, based on
> that entry's row, I need other information from cells in that same row,
> putting them in variables, etc. In some cases, I'll need to do some
> addition with those values.
> Anyway, my, rather primitive, understanding of YAML is that it's a good
> textual database like thing that can be accessed via RUBY. Obviously, my
> "table" is multiple columns and multiple rows. Is YAML OK with multiple
> columns, or, is it meant for just 2 column things, like a hash?
>
> I've played a bit with CSV and James Gray's FasterCSV. It seems more
> like the spreadsheet-like paradigm that I need. I would just like some
> suggestions.
>
> Thank you,
> Peter

Hi,

I have a few thoughts:

- YAML is able to express (almost?) any kind of data structure that
you can have in memory (think of it as a kind of
serialisation/marshalling format)

- YAML is more verbose than CSV if you have more dimensional data (in
case of 2D table, CSV will have one line pre row, YAML will have
several indented lines per row, one per cell)

- How do you store your data in memory? If you have the structure that
fits your usage best, you can store it directly to a file as YAML.

- If you need to lookup the data by file name (and you don't need to
keep the order) it seems to me natural to store the data in a Hash
keyed by filename, with the rest columns as the key's value.

- That reminds me, YAML (as expected) maintains order of Array items,
and shuffles Hash items.

- If you need to hand-edit the data, I would suggest CSV. YAML is much
better that XML at storing sturctured data, still CVS is easier to
edit, especially if there are many rows and many columns.

J.