The Excel portion of your question is not related to the merging of two data structures, and might just be distracting you from solving the actual problem. Solve the first problem (the merging) first.

When you say "merge", you mean one of two things; this:

my @merged = ( \@arr, \@arr1 );

...or this...

my @merged = ( @arr, @arr1 );

You probably are after that second option: my @merged = ( @arr, @arr1 );. Currently you have this:

my @merged = ( @arr, \@arr1 );

...which is probably wrong due to its asymmetry.

Once you determine whether you need the first "merge" or the second one, you should then be able to populate the worksheet like this:

$worksheet1->write_col('A3',\@merged);

UPDATE: After looking at your previous post: Simplest way to match/filter 2d array of values to search in perl, I'm wondering if this is what you're doing:

  1. Start with a 2d array (possibly extracted from a worksheet).
  2. Find all the rows containing some element greater than a certain value.
  3. Derive two arrays; one with rows that passed the threshold, and one containing the remainder, which didn't pass the threshold.
  4. Join the two arrays (which is why, in this question, you wanted to preserve the order).
  5. Write the structure out to a workbook.

If this sounds familiar, what you are doing is called partitioning. A very capable module for partitioning in Perl is Sort::Key::Top. You might look into it to see if it helps simplify your solution.


Dave


In reply to Re: How to merge/join two multidimensional(2D) arrays by davido
in thread How to merge/join two multidimensional(2D) arrays by reaper9187

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.