Passing multiple arrays/hashes as arguments

If we were attempt to pass two arrays together to a subroutine, they would be flattened out to form one large array.

my @fruits  = qw(apple orange pear banana);
my @rodents = qw(mouse rat hamster gerbil rabbit);
my @books   = qw(camel llama panther sheep);

mylist(@fruit, @rodents);

# print out all the fruits and then all the rodents
sub mylist {
        my @list = @_;
        foreach (@list) {
                print "$_\n";
        }
}

If we want to keep them separate, we need to pass the arrays by 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";
        }
}