Another problem you have is in how you are passing your arguments to your subroutine.
$ perl -Mstrict -wE 'sub say_args { my @foo = shift; my @bar = shift;
+say "foo: $_" for @foo; say "bar: $_" for @bar; } my @foo = qw/a b c/
+; my @bar = qw/x y z/; say_args( @foo, @bar );'
foo: a
bar: b
$ perl -Mstrict -wE 'sub say_args { my @foo = shift; my @bar = shift;
+say "foo: $_" for @foo; say "bar: $_" for @bar; } my @foo = qw/a b c/
+; my @bar = qw/x y z/; say_args( \@foo, \@bar );'
foo: ARRAY(0x17b85e8)
bar: ARRAY(0x17b9110)
$ perl -Mstrict -wE 'sub say_args { my $foo = shift; my $bar = shift;
+say "foo: $_" for @$foo; say "bar: $_" for @$bar; } my @foo = qw/a b
+c/; my @bar = qw/x y z/; say_args( \@foo, \@bar );'
foo: a
foo: b
foo: c
bar: x
bar: y
bar: z
As you can see you need to pass references to your arrays (else they will be concatenated, and additionally you will only get one element at a time with
shift), and then dereference them inside the subroutine. See
perlreftut.
Hope this helps!
The way forward always starts with a minimal test.