Okay, lets start with the basics then.

First, your code is bad practice. If you're new to Perl, you're excused, but we'll show you the Right Way (TM) :). The problem is that by having four different hashes, you data is separated. If you want to check the amount of memory left in a particular computer, what do you refer to? One of many psuedo-global variables. The better way to do it is to organize your data into one nested structure, that approaches the way we think of it.

"All well and good," you say "but how do I do that?"

References. (This next section assumes you don't know about references. If you do, too bad, I'm writing it anyway :) )
A good place to learn about references is the perlref man page. I'll give a quick run down here, but it's important to know that I'll gloss over some details, and use some not-technically-correct terminology. References are a scalar value that refers (surprise) to memory address of a perl variable. (Those familiar with C may compare them to "pointers", but aside from a conceptual simularity, the operations you can do are different, so I won't discuss it further). What can you do with this address? Nothing. But you can dereference it, giving you access to the contents of the original variable. And because a reference is a scalar, you can do lots of neat things with it, only some of which I discuss here.

For example, a hash can store only scalars, one for each key. But if a reference is a scalar, you could store a reference to, say, a list for each key of the hash. Suddenly your hash has (effectively) two layers.

In the example you posted, my first solution was to create a list of references to your hashes. merlyn took this to an extreme and separated all your data into nested layers. (Which is good, because it means you can access any discrete piece of information)

You can check out the syntax for creating and dereferencing references in perlref. Ignore all the sections about "soft" references, that's bad practice.

Oh, and the obligatory newbie advice:


In reply to RE:(4) Hash Nightmare by swiftone
in thread Hash Nightmare by Limo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.