Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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";


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]
Discipulus looks for his glasses just to defeat his thirst

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2018-05-20 16:39 GMT
Find Nodes?
    Voting Booth?