Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Anonymous Monk
on Jun 10, 2013 at 17:03 UTC ( #1038113=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

Sorry for not being clear the issue is that the first part of the code is the original code that I have to modify to work using Splice. Since I am a noobie with Perl the bottom code is my attempt which is not working. I need to use splice to make this work as part of my assignment.


Comment on Re^2: Using Splice with Two Arrays within a loop
Re^3: Using Splice with Two Arrays within a loop
by hdb (Prior) on Jun 10, 2013 at 17:11 UTC

    Here is the splice version. Make sure you understand what's going on before you submit to whomever... (there is a twist...)

    #!/usr/bin/perl use strict; use warnings; my @first = qw(Can unlock secret); my @second = qw(you the code?); my @mixed = interleave_words( scalar(@first), @first, @second ); print "Result: @mixed\n"; sub interleave_words { my $count = shift; my @results = splice @_, $count; foreach my $index ( 0 .. $count-1 ) { splice @results, 2*$index, 0, shift; } return @results; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-12-20 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls