in reply to VVP:arrays of the same size.
Another way would be to make a temporary hash and use each. This means you don't care what order stuff is done in, so long as the Nth element of @a is processed with the Nth element of @b.for (my $i = 0; $i < @a; $i++) { # Do stuff with @a and @b }
The first is clearer and easier to work with. Plus, it allows the addition of some @c later on in the future.my %temp; @temp{@a} = @b; while (my ($a_val, $b_val) = each %temp) { # Do stuff with $a_val and $b_val }
Now, if these are parallel arrays, you might want to consider doing the following:
That makes it very clear they are parallel arrays. *shrugs* YMMVuse mapcar; # This is on a node [tye] posted somewhere on PM my @temp_arr = mapcar { \@_ } (\@a, \@b); foreach my $vals (@temp_arr) { # Do stuff with $vals->[0] (from @a) and $vals->[1] (from @b) }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|