Perl Language Lists Using arrayref to pass array to sub


The arrayref for @foo is \@foo. This is handy if you need to pass an array and other things to a subroutine. Passing @foo is like passing multiple scalars. But passing \@foo is a single scalar. Inside the subroutine:

xyz(\@foo, 123);
sub xyz {
    my ($arr, $etc) = @_;
    print $arr->[0]; # using the first item in $arr. It is like $foo[0]