I've been staring at the screen for too long..

It's funny you say it doesn't merge, I've just copied the code from the post and used Data::Dumper to dump $arr at the end and I can see it merged as it should be..

No, the initial position of the member doesn't matter. If we look at an arbitrary first row of two arrefs:

$a->[0] = [qw/f0 f1 f2 f3/]; $b->[0] = [qw/e0 f2 e1 f0 e2];
If the value of the field in $b->[0] matches one already present in $a->[0] then all values in the matching field in the $b->1..$ arrays should be set in the already matched field. So the final array would be like:
$m = [ [qw/f0 f1 f2 f3 e0 e1 e2], [qw/a0 a1 a2 a3 "" "" ""/],# ..and so on all of $a [qw/b3 "" b1 "" b0 b2 b4/],# ..and so on for $b->[1..$]
a0,1,2.. being the first,second,third element of a $a->[x] array and likewise for the b0,1,2 of the $b->[x] array.

Does this make it any clearer?


In reply to Re^3: Merging two array(refs) by kpiti
in thread Merging two array(refs) by kpiti

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.