What happens when @_ is modified?
-
when arrays and references are passed
-
only when references are passed
-
args are not changed
-
Command line args are changed
@, the default array for subroutine arguments, contains aliases to the actual passed elements. When arrays or references are passed, modifying @ changes the original data. For references, this affects the referenced object.
@_ has no connection to command-line arguments (those live in the separate @ARGV array) — that option conflates two unrelated things. In Perl, @_ holds aliases to the actual variables passed into a subroutine, so modifying an element of @_ (e.g., $[0] = ...) changes the caller's original variable, which is most relevant when arrays or references are passed in as arguments. Assigning to the whole @ array, by contrast, breaks the aliasing and does not affect the caller's variables.