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
In reply to Not sure how to populate a hash by aditya1977
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |