I think I have misunderstood some aspects of argument passing to functions in Perl. What\'s the difference between func(\\@array)
and func(@array)
?
AFAIK, in both functions, arguments are passed by reference and in both functions we can change the elements of @array in the main program.
"change the elements of", yes. However, in the func(@array)
case, the sub has no means to make other changes to the array (truncating it, pushing, popping, slicing, passing a reference to something else, even undef'ing it).
I would avoid using the term "passed by reference", since the mechanism is completely different than Perl's references. It is less overloaded :) to say that in the sub, @_
's elements start off aliased to the elements passed to the sub.