I have the below code
use strict;
sub test {
my($greeting, @names) = @_;
my $returnString;
foreach my $name (@names) {
$returnString .= "$greeting, $name!\n";
}
return $returnString;
}
print &test("Hi", "Tim", "Tom", "Chris");
which outputs
Hi Tim! Hi Tom! Hi Chris!
I want to be able to add multiple arrays. I tried modifying my code like the below
my(@greeting, @names) = @_;
print &test("Hi", "Tim", "Hello", "Tom", "Bye", "Chris");
However I have found that this can't be done. From the reading I have done I think I need to pass the arguments as references.
my($greeting, $names) = @_;
my @names = $names;
But I have found this only outputs Hi Tim!
What is the best way to handle this situation?