in reply to Foreach in mulitple arrays
Adding the commas indeed work. However, there's another, more general possibility too: factor the loop body out to a function and use three different foreach loops. Like, instead of
you can writefor (@array1, @array2, @array3) { print "met $_"; }
This works even if you have a more complicated iterator than foreach.my $body = sub { print "met $_"; } for (@array1) { &$body() } for (@array2) { &$body() } for (@array3) { &$body() }
|
|---|