aditya1977 has asked for the wisdom of the Perl Monks concerning the following question:
I have the following script
my %nodemetrics; my @nodelist = qw(server1 server2); my @system_attributes = qw(memory cpu disk network); # Initialise the hash with zeros foreach $node (@nodelist) { foreach (@system_attributes){ $nodemetrics{$node}{$_} = 0; } } print Dumper(\%nodemetrics);
When I run this I get
$VAR1 = { 'server2' => { 'network' => 0, 'memory' => 0, 'disk' => 0, 'cpu' => 0 }, 'server1' => { 'network' => 0, 'memory' => 0, 'disk' => 0, 'cpu' => 0 } };
Now I run an external command which returns pipe delimited data for one server. I store this in an array. For example I might have:
$string="1024|2200|30|100"; @data = split(/\|/,$string);
How do I 'copy' this array into one of the servers data? In other words for a particular server I need to populate its attributes with this array.
I know I could set each attribute one by one but that's cumbersome for a large number of attributes
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Not sure how to populate a hash
by LanX (Saint) on Sep 24, 2014 at 10:06 UTC | |
by aditya1977 (Novice) on Sep 24, 2014 at 10:45 UTC | |
by Athanasius (Archbishop) on Sep 24, 2014 at 12:05 UTC | |
by aditya1977 (Novice) on Sep 24, 2014 at 13:23 UTC | |
by LanX (Saint) on Sep 24, 2014 at 13:35 UTC | |
by LanX (Saint) on Sep 24, 2014 at 10:50 UTC | |
by vinoth.ree (Monsignor) on Sep 24, 2014 at 11:50 UTC | |
by Monk::Thomas (Friar) on Sep 24, 2014 at 12:02 UTC | |
|
Re: Not sure how to populate a hash
by karlgoethebier (Abbot) on Sep 24, 2014 at 14:43 UTC |