in reply to Confused on handling merging values for hash of hashes
Just a few “food for” thoughts here . . .
(1) It does you no good at all if you have a unique-integer “only to serve as the key to a hash.” A hash-key should be something that you search for. It could be a string that combines several fields that you need to search-for at once, e.g. “Mike:24”. If you’re going to choose a hash, choose (or coin) a key that works for you.
(2) It’s perfectly legitimate for one thing (say, a hashref corresponding to “one record,” to be referenced by more-than-one hash at a time, much as database rows might be referenced by more than one index. If you need to store more than one hashref under a single key, simply make the index-hash point to an arrayref containing zero-or-more hashrefs. (Google abut Perl’s auto-vivification feature; also exists().)
(3) If you need to track the person’s possessions, a string is certainly one way to do it. Another way is to use an arrayref. A third is to use a hashref in which the value being stored is just a dummy-value, and the key is what you are actually interested in. When the time comes to produce the list of possessions, e.g. join(", ", sort keys %$myhash).
(4) The most important thing to wrap your head around, with regards to Perl, is the all-important idea of references. There is, for example, no such thing as a hash “of hashes.” No, what the hash actually contains is a reference to something else. (And if that something-else is a hash, we call the reference to it a “hashref.” But, “the thing being referred to” is one thing, and every one of the references to it are separate, distinct, memory objects of a “scalar” type. It is quite common for there to be things hanging-around in memory which are anonymous values: no variable contains or refers-to them directly. It’s perfectly all right for there to be more-than-one reference to the same (anonymous, or not ...) thing. Perl has a very efficient and powerful memory manager which maintains reference-counts for everything and which keeps storage tidy and neat.
(5) Perl’s syntax is also designed around the notion that “there’s more than one way to say the same thing,” especially when it comes to referring to things in memory. This can be quite confusing if you are more accustomed to strongly-typed languages, “the one ‘right’ way,” and getting rewarded with syntax error messages at compile-time if you don’t write your code in just that way. Quite frankly, I found it baffling at first. Even when you use strict; use warnings;, Perl is an extremely dynamic system. This is part of what makes it so damned powerful, but do not apologize for feeling bewildered.