If we were to attempt to pass two arrays together to a function or subroutine, they would be flattened out to form one large array:
mylist(@fruit, @rodents);
# print out all the fruits then all the rodents
sub mylist {
my @list = @_;
foreach (@list) {
print "$_\n";
}
}If we want them kept separate, pass references:
myreflist(@fruit, @rodents);
sub myreflist {
my ($firstref, $secondref) = @_;
print "First list:\n";
foreach (@$firstref) {
print "$_\n";
}
print "Second list:\n";
foreach (@$secondref) {
print "$_\n";
}
}