Oh, it's far clearer with the nested loops example ^^. You could also do:

for(@a1=`cat file`;$a[0]=shift @a1;@a1) { for(@a2=@b;$a[1]=shift @a2;@a2) # could be "for(;$a[1]=shift @b;@b)" + if you don't care about emptying @b { for(@a3=grep /4/, @c;$a[2]=shift @a3;@a3) { <Statements>; } } }
but that's kind of ugly. Maybe you could use that with source filtering to have a lighter syntax ...


If you intend to do that sort of things often in your script you could use Perl Prototypes to add that kind of syntax to your program:

sub with {for (@{$_[1]}){$_[0] = $_;$_[2]();}} sub in { \@_ } sub run(&) { $_[0] }
Then you could write :
# parenthesis mandatory after in, bad idea after with and the commas c +an't be ommited with $a[0], in(qw/Bonjour Bonsoir/), run { with $a[1], in ("Paul", "Jack", "Lord Voldemort"), run { say "@a"; }; # semi-colon mandatory }; # same here
Bonjour Paul Bonjour Jack Bonjour Lord Voldemort Bonsoir Paul Bonsoir Jack Bonsoir Lord Voldemort
But I did that because it was fun, and a bit of a challenge, but that's not very practical. You probably have to stick with my first answer.


In reply to Re^5: Using an array element as a loop iterator by Eily
in thread Using an array element as a loop iterator by gurpreetsingh13

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.