Peter Buckley <jacob14years4rachel / yahoo.com> wrote:

> I have string1, stringA (which won't be known till later) that is
> associated with string1, and then stringB and potentially stringC and
> stringD which are all associated with string1 and stringA.

That sounds like a hash where each value is a hash where each value is
an array.

> So I'm thinking that I want a hash, big_hash, with string1 as the key,
> and the value is another hash, string1_hash, with stringA as the key and
> the value is an array containing stringB,stringC,stringD.

Great idea!

> I realize I could name string1_hash anything, but I'm going to need
> multiple hashes as I iterate over a list of string1, string2, string3.
> I'd like big_hash to be somewhat permanent so I can re-use it elsewhere.

There seems to be some confusion about the notion of "name" underlying
all of this. There are not really any "names" in this story. Ruby isn't
about "names". It's about pointers. string1_hash doesn't *have* a
"name". It doesn't *need* a name. It is the value of some entry in
big_hash. As long as you have a pointer to big_hash, you will always
have access to its keys and values, and every one of those values is a
hash of arrays, where the key is string1, string2, string3, whatever.
You are there.

So now the only question seems to be what you mean about the permanence
of big_hash. Do you mean you'd like to store it between runs of your
script? I'd use yaml for that. If you only mean that you need to be able
to access it in various places during a single run of the script, then
either make your pointer to it global or pass it around as a parameter.

By the way, you *could* make all this a bit more rigorous by expressing
it all as a class. I mention this only because a class might help you
formalize the rules for the structure here. You don't *need* to do that,
but it might help you catch errors down the road. m.

-- 
matt neuburg, phd = matt / tidbits.com, http://www.tidbits.com/matt/
Leopard - http://www.takecontrolbooks.com/leopard-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com