in reply to Using Splice with Two Arrays within a loop
You might find it easier by passing references to your arrays:
#!/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, $first, $second) = @_; my @results; die unless $#$first == $#$second; return map { $$first[$_], $$second[$_] } 0..$count-1; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using Splice with Two Arrays within a loop
by AnomalousMonk (Archbishop) on Jun 10, 2013 at 18:09 UTC | |
Re^2: Using Splice with Two Arrays within a loop
by Anonymous Monk on Jun 10, 2013 at 17:32 UTC | |
by Anonymous Monk on Jun 10, 2013 at 18:28 UTC |
In Section
Seekers of Perl Wisdom