Hi, I have three arrays with elements shown below: array1 = 1,2,3 array2 = a,b,c,d,e,f,g array3 = I,II,III I want it displayed like this:
1,a,I 2,a,I 3,a,I 4,a,I 5,a,I 1,a,II 2,a,II 3,a,II 4,a,II 5,a,II 1,a,III 2,a,III 3,a,III 4,a,III 5,a,III 1,b,I 2,b,I 3,b,I 4,b,I 5,b,I 1,b,II 2,b,II 3,b,II 4,b,II 5,b,II 1,b,III 2,b,III 3,b,III 4,b,III 5,b,III and so on.
I am trying the following but its not able to loop correctly.
my $i = $j = $k = 0; for my $i (@array1) { for my $j (@array2) { for my $k (@array3) { print "$array1[k],$array2[j],$array3[i],\n"; $k++; } $j++; } $k++; }
How can I fix this? Thanks in advance for your help.

In reply to Printing from three arrays by oysterperl

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.