cucugirl
asked on
hashes and array of hashes
I have an array of hashes and a hash, i needed to check the values of both and if they are different replace the key/value pair in the array of hashes with the key value pair in the hash. For example the key value pair NAME => 'Y' in the AoH is different from the %default, I need to replace this for NAME=>'N' in the array of hashes. Can somebody help me with this?
Thanks!
Thanks!
$VAR1 = [
{'NAME' => 'Y',
'FILE' => 'file.txt',
'YEAR' => '1988'}
]
%default = {'MODE' = '2', ''NAME' => 'N','FILE' => 'file.txt', 'YEAR' => '1987'}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#sorry, I was thinking $VAR1 would override the default, but it sounds like you want the default to override $VAR1
@$VAR1 = map{ {%$_, %default} } @$VAR1 ;
#or
@{$_}{keys %$_}=@default{keys %$_} for @$VAR1;
@$VAR1 = map{ {%$_, %default} } @$VAR1 ;
#or
@{$_}{keys %$_}=@default{keys %$_} for @$VAR1;
{'NAME' => 'Y',
'FILE' => 'file.txt',
'YEAR' => '1988'}
];
%default = ('MODE' => '2', 'NAME' => 'N','FILE' => 'file.txt', 'YEAR' => '1987');
@$VAR1 = map{ {%default,%$_} } @$VAR1 ;