in reply to How come @_ gets changed here?

Perl arguments are passed by reference. Change them in the sub, and they'll change in the caller and vice-versa.

Replies are listed 'Best First'.
Re^2: How come @_ gets changed here?
by Lotus1 (Vicar) on Jun 12, 2017 at 13:59 UTC

    According to perlsub inside a subroutine the elements of @_ are aliased to the items in the list that are passed to the subroutine. Passing by reference means you pass one or more references in the arguments to the subroutine. Then elements of @_ are aliased to the references and you can make local copies inside the subroutine.

      "Pass By Reference" (vs. "Pass By Value") is a general computer science term which is implemented as "aliasing" in Perl.

      Perl's "references" are totally different.

      update

      Context matters: Canadians are North Americans proud not to be Americans. ;)

      update

      OK, I consider this perlsub#Pass-by-Reference a documentation bug.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!