G
Graham Drabble
Hi,
I have 2 arrays
%a = ('apples' => 2,
'pears' => 1);
%b = ('apples' => 3,
'pears' => 6);
Want I want is to be able to get
%c = ('apples' => 5,
'pears' => 7);
This can be achieved by
my %c;
foreach my $key (keys %a){
$c{$key} = $a{$key} + $b{$key};
}
but I was wondering if there was any way to do it without the loop.
Any ideas?
I have 2 arrays
%a = ('apples' => 2,
'pears' => 1);
%b = ('apples' => 3,
'pears' => 6);
Want I want is to be able to get
%c = ('apples' => 5,
'pears' => 7);
This can be achieved by
my %c;
foreach my $key (keys %a){
$c{$key} = $a{$key} + $b{$key};
}
but I was wondering if there was any way to do it without the loop.
Any ideas?