Personally I prefer to use a non-iterator style, so I combine (my own) zip with pair from List::Pairwise.

for (pair(zip($array1, $array2))) { my ($x, $y) = @$_; # It's often descriptive to name the values. ... }
The main reason I like pair over natatime is that it's easy to combine with any expression/subroutine that requires the whole list and in particular sort (but also map and grep). For instance:
for ( sort { $a->[0] <=> $b->[0] or $a->[1] cmp $b->[1] } pair zip($array1, $array2) ) { my ($number, $char) = @$_; ... }
The reason I don't use zip from List::MoreUtils is that it's prototyped with (\@\@;\@...) which I find counter-intuitive, as I imagine you do too as you passed in $array1 instead of @$array1. It's also more in the way than it's helping, as I frequently end up with wanting to zip the result of an expression instead of an array or having a list or an array holding array references.

lodin


In reply to Re^2: parallel procesing (List::Pairwise) by lodin
in thread parallel procesing by baxy77bax

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.