Here's a solution with just map and grep:

#!/usr/bin/env perl use strict; use warnings; my $data1 = [ { 'NAME' => '1PAUL DY', 'DATE' => '12009-05-05', 'NUMBER' => '1000 +01', 'ACC' => '1A1A', }, { 'NAME' => '2PAUL DY', 'DATE' => '2011-01-05', 'NUMBER' => '20033 +1', 'ACC' => '2A3B', }, { 'NAME' => '4PAUL DY', 'DATE' => '42011-01-05', 'NUMBER' => '4200 +331', 'ACC' => '6A4B', }, ]; my $data2 = [ { 'EXT1' => '1b', 'EXT2' => '12b', 'EXT3' => '13b', 'EXT4' => '14 +d', 'ACC' => '1A1A', }, { 'EXT1' => '2b', 'EXT2' => '2b', 'EXT3' => '2b', 'EXT4' => '2d', + 'ACC' => '2A3B', }, { 'EXT1X' => '4b', 'EXT2X' => '4b', 'EXT3X' => '4b', 'EXT4X' => ' +4d', 'ACC' => '4A4B', }, ]; my @merged = map { { %{$data1->[$_]}, %{$data2->[$_]} } } grep { $data1->[$_]{ACC} eq $data2->[$_]{ACC} } 0 .. $#$data1; # Check results use Data::Dump; dd \@merged;

Output:

$ pm_1148951_merge_arrays.pl [ { ACC => "1A1A", DATE => "12009-05-05", EXT1 => "1b", EXT2 => "12b", EXT3 => "13b", EXT4 => "14d", NAME => "1PAUL DY", NUMBER => 100001, }, { ACC => "2A3B", DATE => "2011-01-05", EXT1 => "2b", EXT2 => "2b", EXT3 => "2b", EXT4 => "2d", NAME => "2PAUL DY", NUMBER => 200331, }, ]

— Ken


In reply to Re: Merging Data into one array by kcott
in thread Merging Data into one array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.