You can't pass arrays (or hashes) to subs. You can only pass scalars to subs. (And they can only return scalars.)
What we can do is pass a reference to an array (or hash). References are scalars. And in fact, this is what you are doing.
The problem is that you are assigning it to an array. An array that always contains exactly one scalar just makes things complicated for nothing. It should be assigned to a scalar. And it should be treated as a reference.
sub arrayPrint {
my ( $x, $y, $array ) = @_;
for my $e ( @$array ) {
say $fh "$x$y$e";
}
}
arrayPrint( $x, $y, \@array );
The other approach would be to pass each element of the array to the sub.
sub arrayPrint {
my ( $x, $y, @array ) = @_;
for my $e ( @array ) {
say $fh "$x$y$e";
}
}
arrayPrint( $x, $y, @array );
or
sub arrayPrint {
my $x = shift;
my $y = shift;
for my $e ( @_ ) {
say $fh "$x$y$e";
}
}
arrayPrint( $x, $y, @array );