How to traverse multiple lists at a time in perl
This article is about how perl traverses more than one list at a time. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Traversing multiple lists at a time in perl
In general, when we iterate through multiple related lists at the same time, we often traverse with array subscripts:
My @ a = (...); my @ b = (...); my @ c; foreach my $I (0.. $# a) {my ($a, $b) = ($a [$I], $b [$I]); push @ c, $a + $b;}
In fact, it can also be like this:
Use List::MoreUtils qw (pairwise); my @ c = pairwise {$a + $b} @ a, @ b
Pairwise is only suitable for two lists, and three lists do this:
Use List::MoreUtils qw (each_array); my $ea = each_array (@ a, @ b, @ c); my @ d; while (my ($a, $b, $c) = $ea- > () {push @ d, $axium baccalaureate;} Thank you for reading! This is the end of this article on "how to traverse multiple lists in perl". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!