Hi aditya1977
Lets try this one.
use strict; use warnings; use Data::Dumper; my %nodemetrics; my @nodelist = qw(server1 server2); my @system_attributes = qw(memory cpu disk network); # Initialise the hash with zeros my ($node); foreach $node (@nodelist) { foreach (@system_attributes){ $nodemetrics{$node}{$_} = 0; } } print Dumper(\%nodemetrics); my $string="1024|2200|30|100"; my @data = split(/\|/,$string); my @keys = keys %{$nodemetrics{'server1'}}; my $hashref = $nodemetrics{'server1'}; @$hashref{@keys}=@data; $nodemetrics{'server1'}=$hashref; print Dumper (\%nodemetrics);
In reply to Re^3: Not sure how to populate a hash
by vinoth.ree
in thread Not sure how to populate a hash
by aditya1977
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |