We will get you there, eventually, ;-)... Ed Sickafus wrote:
I am not understanding this correctly, lets see if we can work around it for now. but do you mean 'tie' as in the Perl sense of 'tie' or in the english verb 'tie' sense?Although you all are trying, I'm still not getting it -- namely, how to use the hash names in a HoH. My reference shows the following template for a HoH:outermost hash | inner level of hashes | | innermost key/value pairs | | | \/ \/ \/ %hash = ( fruits => { favorite => "apples", 'second favorite' => "apples", }, vegetables => { favorite => "corn", 'second favorite' => "peas", 'least favorite' => "turnip", }, meats => { favorite = > "chicken", 'second favorite' => "beef", }, ); The outermost %h: I wish to use "%hash" as my database file "data.db" which will tied to a "%hashhandle" pointing to %hash when called by my script.
The next level of %h's:fruits, vegetables, and meats are simply strings that are keys in the %hash hash. So think of the outer hash as just a normal hash, nothing special that contains keys and values like normal. If you were to dump the outer hash it would look something like:
It looks like "fruits", "vegetables", and "meats" in the template are hashes
that can be appended each time the outer hash is called by a script -- if,
in fact, appending occurs sequentially inside of the final ");".
meats -> HASH(0x80c0eb8)
fruits -> HASH(0x804c00c)
vegetables -> HASH(0x805f9e4)
Because you are dealing in hashes *order means nothing!* so the sense that it is sequential is completely lost when the data 'comes back out'. If ordering matters to you then you should not use a hash, or sort by a key that you create manually (see below).
At least
that is what I want to do; append an inner hash each time the script is run. However, I need the names of these inner hashes to change from run to run (i.e., to go from fruits to vegetables, then to meats, etc.). Actually "fruits", "vegetables", and "meats" are keys of the associated values which happen to be another set of key/value pairs.
Correct.
The innermost level of key/value pairs will, in my case, have the same four or five key names for each inner level hash. The template shows that they can vary in number and titles.
Yes.
In my case, "fruits" represents (to me) the name of a set of key/value pairs appended to %hash on its first call. "vegetables" represents the name of the second set of key/value pairs appended to %hash on its second call. Each time the database hash is called a hash is appended. In thhis template, its name seems to be known a priori. My script will need to generate a name for this level of hashes on each run of the script.
Correct that it is known apriori, but it need not be. Should work.
That should work as it is unique (assuming your calls don't come within the same second). The key of the outer hash (which is how you will access the inner data) *can* be set dynamically, but what you were asking was can the name of a variable (which is something different) be set dynamically which is "yes, but shouldn't.". because what is stored is a key in a hash, not a variable name, in your case it can be done.It occured to me to use the time/date of each call to the script as a name for the associated inner-hash that will be generated and then appended. But, I understand (somewhat unclearly) that this is not allowed.
Hopefully this clears things up a little. you might check out perldoc perlreftut and perldoc perlref if you haven't already.Where am I off base in my understanding of HoH's?
Short hand, it doesn't contain spaces, so Perl will know what to do, personally I don't like it because it is less readable and to me sloppy, but technically it is correct.Ed PS: Why is the name favorite not quoted, 'favorite', as is 'second favorite' in the template?
Can you post a sample of how your data is generated and what you are looking for in your data structure? The other part i am confused about is when you talk about running at different times, are you referring to something external you are calling using system, or the like, or are you storing/re-reading your hash, each time, etc?
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]