programming-examples/perl/Subroutine/Passing arrays to a function.pl
2019-11-15 12:59:38 +01:00

23 lines
463 B
Perl

#!/usr/bin/perl
use warnings;
use strict;
my @array1 = ( 1 .. 8 );
my @array2 = ( 'a' .. 'e' );
my @mixed = arrayMixer( \@array1, \@array2 );
print( "@mixed\n" );
sub arrayMixer
{
my @firstArray = @{ $_[ 0 ] };
my @secondArray = @{ $_[ 1 ] };
my ( $first, $second, @array );
while ( ( $first = shift( @firstArray ) ) && ( $second = shift( @secondArray ) ) ) {
push( @array, $first, $second );
}
return @array;
}