in reply to combine two AoHs
map and a little casting magic does the trick. Note the %{$a[$_]} that turns the hash ref returned by $a[$_] into a hash.
BTW, you should perhaps avoid using a and b - even when they are not scalars they can cause confusion due to $a and $b being used for sort parameters. (Yes, I know this is a trivial sample, but good habits are good habits.)
use strict; use warnings; use Data::Dump::Streamer; my @a_ = ({ domain => 'adomain.com', data => 'adata', }, { domain => 'bdomain.com', data => 'bdata', }); my @b_ = ({ domain => 'adomain.com', otherdata => 'astuff', }, { domain => 'bdomain.com', otherdata => 'bstuff', }); my @c = map {{%{$a_[$_]}, %{$b_[$_]}}} 0..$#a_; Dump (\@c);
Prints:
$ARRAY1 = [ { data => 'adata', domain => 'adomain.com', otherdata => 'astuff' }, { data => 'bdata', domain => 'bdomain.com', otherdata => 'bstuff' } ];
|
|---|