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

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

by gponcho (Initiate)
on Jun 10, 2013 at 21:04 UTC ( #1038159=note: print w/ replies, xml ) Need Help??


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

Thanks for the response however as I mentioned I am new to this so where would I add the code you gave in the following script:

#!/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; }
Again many thanks


Comment on Re^6: Using Splice with Two Arrays within a loop
Download Code
Re^7: Using Splice with Two Arrays within a loop
by hdb (Parson) on Jun 10, 2013 at 21:09 UTC

    End of day in Europe now. Good night!



Re^7: Using Splice with Two Arrays within a loop
by AnomalousMonk (Monsignor) on Jun 10, 2013 at 22:25 UTC

    The code for  sub interleave_words { ... } in hdb's reply is an alternative definition of the subroutine. Put it in place of the definition of the subroutine of the same name you have here.

Re^7: Using Splice with Two Arrays within a loop
by hdb (Parson) on Jun 11, 2013 at 07:22 UTC

    This develops into quite an interesting conversation. I would be grateful if could tell a bit more about the assignment you mentioned.

    I am wondering whether understanding the solution is part of the assignement. If you carefully compare the two previous pieces of code, you should be able to work out where the die statement fits in. It does not even have to be modified in any way. If you cannot work it out, then you would not be able to answer any kind of question about the solution you submit.

    Or is the assignment to find someone to write the code for you based on the given spec?

    Please do not understand me wrong! I quite like to provide answers on PM, so I don't mind either way. I am only curious what you will do you with the information provided here and whether it will really help you.

    The other thing I am wondering is about the person who gave you the assignment. Surely, s(he) must be aware about this website and will compare answers given here with submitted answers to the assignment?

      Thanks I figured out where to place the code. As I mentioned this is a part time class I am taking to get familiar with programming. I appreciate the input you have given. Just drew a blank on this assignment.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-08-23 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls