Multiple choice technology programming languages

What happens when @_ is modified?

  1. when arrays and references are passed

  2. only when references are passed

  3. args are not changed

  4. Command line args are changed

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

@, 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.

AI explanation

@_ 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.