Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Using Splice with Two Arrays within a loop

by davido (Archbishop)
on Jun 10, 2013 at 15:52 UTC ( #1038104=note: print w/ replies, xml ) Need Help??

in reply to Using Splice with Two Arrays within a loop

I don't quite understand why you need a different approach to the same goal in your second snippet. I do think it's clever to have passed a count value for the first array as a way of dealing with the fact that Perl flattens lists, but references are built into the language, in part, to deal with that problem more conveniently. Passing a count is so... "C". ;)

However, if I were doing it, I would just use List::MoreUtils "zip" function (also known as mesh):

use List::MoreUtils qw( zip ); my @first = qw( can unlock secret ); my @second = qw( you the code? ); my @mixed = zip @first, @second; print "@mixed\n";


Comment on Re: Using Splice with Two Arrays within a loop
Select or Download Code
Replies are listed 'Best First'.
Re^2: Using Splice with Two Arrays within a loop
by Anonymous Monk on Jun 10, 2013 at 17:34 UTC

    Sorry to clarify I have an assignment that requires the following to be done: "This program can be made both shorter and faster by using a built-in function named splice that will remove a specified number of elements from the @_ array at once, rather than the one-at-a-time that shift does." As you can see from my output I am doing something wrong. Can someone help me out. I need to use splice to resolve this.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2015-11-29 23:37 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 (754 votes), past polls