Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^2: Using Splice with Two Arrays within a loop

by AnomalousMonk (Canon)
on Jun 10, 2013 at 18:09 UTC ( #1038131=note: print w/ replies, xml ) Need Help??

in reply to Re: Using Splice with Two Arrays within a loop
in thread Using Splice with Two Arrays within a loop

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!)

Comment on Re^2: Using Splice with Two Arrays within a loop
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038131]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2015-12-01 00:58 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (790 votes), past polls