You are out of luck with the syntax you wanted. Syntax is syntax, which you have to strictly follow. Logically, You might have a point to use an array element as the loop variable (as long as it is a scalar, however you must realize the difficulty that this schema introduced, as it is not possible to determine the type of an array element statically, thus it is wise not to introduce what you wanted into a language.), but that's not how the language is defined.

You still can do what you wanted to do, inside each level of your quadruple loop, just push the loop variable into an array.

for my $i (...) { push @iter, $i; ... for my $j (...) { push @iter, $j; ... for my $k (...) { push @iter, $k; ... for my $l (...) { push @iter, $l; ... } } } }

On the other hand, I trust that, you realize, the inner loops have access to outter loop variables. The reason to push them into an array is not for gaining access of their values, but rather other convenience that you are seeking.


In reply to Re^2: foreach with array elements problem by pg
in thread foreach with array elements problem by OnionKnight

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.