Oh, it's far clearer with the nested loops example ^^. You could also do:
but that's kind of ugly. Maybe you could use that with source filtering to have a lighter syntax ...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>; } } }
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:
Then you could write :sub with {for (@{$_[1]}){$_[0] = $_;$_[2]();}} sub in { \@_ } sub run(&) { $_[0] }
# 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
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.Bonjour Paul Bonjour Jack Bonjour Lord Voldemort Bonsoir Paul Bonsoir Jack Bonsoir Lord Voldemort
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |