BrowserUk has given a good solution, but let me come back to your code to point out your errors.

You are opening the TEMP filehandle for writing n times, with n being the number of elements of one of your arrays. And you're writing all your data n times, each time clobbering what you've written in the previous iteration.

From your description of the problem, you don't need nested loops, you only need one loop, because the same loop variable ($i in the code below) can access the corresponding items in both arrays.

open my $TEMP, ">", "TMPFILES/$i.tmpfile" or die "cannot open output f +ile $!"; for $i ( 0 .. $#AoA_first ) { print $TEMP "$row_first->[$i]\t$row_second->[$i]\n"; } close $TEMP;
The code above is essentially the same, in a less concise form, as BrowserUk's solution.

In reply to Re: Efficient way to print 2 columns from 2 Array of Arrays next to each other by Laurent_R
in thread Efficient way to print 2 columns from 2 Array of Arrays next to each other 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.