Oh, would it? So the for loop would open the second series of files as many times as specified in the first series of files?
Yes, if you have nested loops, you would open the files of the second dataset once for each iteration over the first dataset. So, assuming you have five items in your first dataset, you would open 5 times each file of the second dataset.

If you don't believe me, try to run the following code:

for my $i (1..5) { for my $j (1..3) { print "i = $i; j = $j \n"; } }
and observe how many lines you print (should be 15). Each value of $j is printed 5 times. That may be OK is you want to display some combinations (say print out the multiplication tables), but you don't want to open and read each file of the second data set 5 times. And that's even more true if you have more files.

How do you want to combine them for your computations? All of them together? Or pairwise between the two dataset? Like the first matrix from the $i data set with the first one from the $j data set? Or each matrix of the $i data set with each matrix from the $j data set (a kind of Cartesian product)? or something else?

Whichever way, read each file only once and store its content in a separate matrix in memory (say an array of arrays), and make your calculations at a later point. Since you'll have several matrices, you should end up with an AoAoA (array or arrays of arrays) or possibly a HoAoA (hash or arrays of arrays), or some similar data structure, depending on how you want to make the calculations later.


In reply to Re^7: reading files in @ARGV doesn't return expected output by Laurent_R
in thread reading files in @ARGV doesn't return expected output by fasoli

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.