From: Peter Buckley Date: 2009-02-27T07:25:52+09:00 Subject: Re: dynamic variable names or using a variable as another's name matt neuburg wrote: > Peter Buckley wrote: > >> string, so bigHash has 5 keys. The problem I'm having is that the value >> of each of the 5 keys is the same - string1_hash. > > Because you *set* them all to string_hash, in this line: > >> > bigHash[string1] = string1_hash > > What were you *trying* to do? Right, that example I'm giving is incorrect - I want to set them like this (sorry, more perl-ish-ness): bigHash[string1] = ${string1}_hash bigHash[string2] = ${string2}_hash ... In my example, the local variable named string1 is changing each time we go through the loop, so what is actually happening is like this (still not doing what I want, assigning the same hash to each unique key): bigHash["12345"] = string1_hash bigHash["54241"] = string1_hash bigHash["86744"] = string1_hash ... > Also, don't you have this upside down? I thought we agreed you were > going to have *one* key called string1, whose value was an array, and > you were going to put 5 different things into that array. I don't see > you doing any of that. > > m. In bigHash I'm going to have one key for string1 (actually equal to string1, "12345") but an arbitrary number of keys like that - in my example (and hopefully clearer above) I have 3 keys each consisting of a unique string. I want each of their values to be a hash that contains a single key that evaluates to a different string, and the value of that key is the array containing one or more yet different strings. But I can't even get to the point where I have a unique hash as the value for each of my keys - after doing more reading I think I should be using the #{string1}_hash syntax to conveniently name my pointers to the unique hashes I'm creating each time through my iteration. Does that make more sense? Sorry my attempts to simplify my example have been confusing. Thanks for your help so far Matt, it is really helping me to "discuss" it with another person who knows more about Ruby than I do. -- Posted via http://www.ruby-forum.com/.