Array References

To solve the problem we will use references. Prefixing the array with a back-slash \ creates a reference to it.

my $names_ref  = \@names;

print $names_ref;      # ARRAY(0x703dcf2)


but it will be probably more readable to write


or even

@{ $names_ref }

Once we know all this we can pass a reference to a function, within the function we can dereference the array and we get back the original array.

use strict;
use warnings;

my @names = qw(Foo Bar Baz);

my $names_ref  = \@names;
print "$names_ref\n";         # ARRAY(0x703dcf2)

print "@$names_ref\n";        # Foo Bar Baz
print "@{ $names_ref }\n";    # Foo Bar Baz

Passing two arrays to a function