Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

Dave


Comment on Re: Using Splice with Two Arrays within a loop
Select or Download Code
Re^2: Using Splice with Two Arrays within a loop
by Anonymous Monk on Jun 10, 2013 at 17:34 UTC
    Hi,

    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.

    Thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-07-07 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls