Jan Svitok wrote:
> On 8/23/06, Peter Bailey <pbailey / bna.com> wrote:
>> "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.


Thanks, Jan. My data originally came from a mainframe ASCII export, so, 
it looks like a 2D table, delineated with spacebands. I've tweaked it 
now so it's just using tabs, and I've even imported it into a 
spreadsheet. I guess it's much more like a CSV format now than a YAML 
format.

I have one question to your response. You say that I could store the 
data in a hash keyed by a filename, which I have done in the past, but, 
then you say that the rest of the columns, of which there are many, 
could be the key's value. How can you have multiple entries for a key 
value? A hash is only a "2-column" entity, isn't it, one key, one value? 
Do I just make all the cells in a row one value, with a comma or 
something between them as a way to distinguish each cell? In other 
words, use the has to match the incoming filename, then, make the row 
that it's in an array and take it from there? (I'm thinking out loud 
here.)

Thanks again,
Peter


-- 
Posted via http://www.ruby-forum.com/.