This merges the list of hashes by storing them temporarilly in the %merge hash and indexing them by 'domain'. You can omit the $to_merge temporary if you're willing to get a bit more ugly syntax.
my @c = merge_aoh_by_domain( @a, @b ); sub merge_aoh_by_domain { my %merge; for my $domain_ref ( @_ ) { # less ugly my $to_merge = $merge{$domain_ref->{domain}} ||= {}; @$to_merge{ keys %$domain_ref } = values %$domain_ref; # ugly # @{$merge{$domain_ref->{domain}}{ keys %$domain_ref } = value +s %$domain_ref; } return values %merge; }
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re: combine two AoHs
by diotalevi
in thread combine two AoHs
by alienhuman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |