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