I knew that it would be (and glad that it was) just a matter of time before you posted a Perl6 and zip operator solution.

I've been trying to figure out how to do that (before you made your post) using Perl 6 and the zip operator. Thanks for posting an example. For some reason I was expecting that the syntax should look more like this:

for( @male Z @female )->[$m,$f] { # .... }

But apparently not. ;) Also, how would you push a stringified concatenation onto a new array? In Perl5 either of these would do WIM:

my @married; foreach( 0 .. $#male ) { push @married, "$male[$_] $female[$_]"; } # OR ..... my @married = map { "$male[$_] $female[$_]" } 0 .. $#male; # OR with List::MoreUtils::pairwise my @married = pairwise{ "$a $b" } @male, @female;

...or you could forgo interpolation and use the (.) dot operator.

I've been puzzling over a Perl6-ish, Zip-operator-ish way to do the same.


Dave


In reply to Re^2: how to avoid using index of array by davido
in thread how to avoid using index of array by Achilles_Sea

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.