Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
You might find it easier by passing references to your arrays ...

But if you're going to do that, you might as well go all the way and dispense with the count argument altogether as mentioned by davido. In fact, this might actually be a good use for prototyping. Of course, if you use a prototype, you just end up with a version of  mesh() that is specialized for two arguments (easily generalized) and does array-size checking, which  mesh() doesn't. Still...

>perl -wMstrict -le "use List::MoreUtils qw(mesh); use Data::Dump; ;; my @first = qw(Can unlock secret); my @second = qw(you the code?); ;; sub interleave_words (\@\@); ;; my @mixed = interleave_words(@first, @second); print qq{Result: '@mixed'}; ;; sub interleave_words (\@\@) { die 'array sizes differ' unless $#{$_[0]} == $#{$_[1]}; goto &mesh; } ;; my @ra = qw(a b c); my @rb = qw(1 2 ); dd [ mesh @ra, @rb ]; " Result: 'Can you unlock the secret code?' ["a", 1, "b", 2, "c", undef]

(Note for anonymous OPer: Don't try this at school unless you really understand what's going on!)


In reply to Re^2: Using Splice with Two Arrays within a loop by AnomalousMonk
in thread Using Splice with Two Arrays within a loop by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (14)
    As of 2014-08-22 15:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (159 votes), past polls