This seems like a rather poorly defined problem. Let me try to reconstruct what you are trying to do:

So one way to address this problem is to have a hash keyed by server name, and each hash entry's value is a reference to an array of values (server_name, CPU utilization).

Try something like this (untested) code to accumulate total CPU usage:

use strict; use warnings; my %server_hash = ( 'server1' => ['cluster1',0], 'server2' => ['cluster1',0], 'server3' => ['cluster2',0], 'server4' => ['cluster2',0] ); my %cluster_totals = (); foreach my $this_server(keys %server_hash) { $server_hash{$this_server}->[1] = getCPUUtilization($this_server); $cluster_totals{$server_hash{$this_server}->[0]} += $server_hash{$th +is_server}->[1]; } foreach (keys %cluster_totals) { print "Cluster: $_ \t $cluster_totals{$_}\n"; }

Granted, I'm using an extra hash where I probably don't need to, and this solution is off-the-cuff. But it might provide you with a starting point. The nice thing about a hash of array references is that it is extensible when you need to store yet another attribute of the server.


In reply to Re: clusters with hashes by ptum
in thread clusters with hashes by Anonymous Monk

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.