http://www.perlmonks.org?node_id=155866


in reply to Passing references to a sub.

The other use of references is when you need to pass two arrays (or a hash and an array) into a sub.
Consider:
my @array1 = ("foo", "foo1", "foo2"); my @array2 = ("bar", "bar1", "bar2"); print_data(@array1, @array2); sub print_data { @array1 = @_; #array1 gets all of @_ @array2 = @_; #array2 also gets all of @_ }
vs
print_data(\@array1, \@array2); sub print_data { my @data1 = @{$_[0]}; #dereferences first array into @data1 my @data2 = @{$_[1]}; #dereferences second array into @data2 }
The second version is more often than not what you actually want.