#!/usr/bin/perl
use strict;
use warnings;
my @first = qw(Can unlock secret);
my @second = qw(you the code?);
my @interleave;
push @interleave, grep {$_} (shift @first), shift @second
while @first || @second;
print "@interleave";
####
#!/usr/bin/perl
use strict;
use warnings;
my @first = qw(Can unlock secret);
my @second = qw(you the code?);
splice @first, @second, 0, pop @second while @second;
print "@first";
##
##
...
splice @first, $_, 0, $second[$_ - 1] for reverse 1 .. @second;
print "@first";
##
##
my @new;
splice @new, 0, 0, $first[$_], $second[$_] for reverse 0 .. $#second;
print "@new";
##
##
#!/usr/bin/perl
use strict;
use warnings;
my @first = qw(Can unlock secret);
my @second = qw(you the code?);
dumpArrays('start', \@first, \@second);
splice(@first, 1, 0, @second[0,-2]);
dumpArrays('first', \@first, \@second);
my @newArray = @first;
splice(@newArray, 5,0,@second[0,2]);
dumpArrays('na', \@first, \@second, \@newArray);
my @newArray1 = @newArray;
splice(@newArray1, 2,1);
dumpArrays('na1', \@first, \@second, \@newArray1);
my @newArray2 = @newArray1;
splice(@newArray2, 4,1);
dumpArrays('na2', \@first, \@second, \@newArray2);
my @newArray3 = @newArray2;
splice(@newArray3,3,0, @second[1,1]);
dumpArrays('na3', \@first, \@second, \@newArray3);
sub dumpArrays {
my ($msg, @arrays) = @_;
printf "%-10s %s\n", $msg, join '|', map {"@$_"} @arrays;
}
##
##
start Can unlock secret|you the code?
first Can you the unlock secret|you the code?
na Can you the unlock secret|you the code?|Can you the unlock secret you code?
na1 Can you the unlock secret|you the code?|Can you unlock secret you code?
na2 Can you the unlock secret|you the code?|Can you unlock secret code?
na3 Can you the unlock secret|you the code?|Can you unlock the the secret code?