title: Are Perl subroutines call-by-reference or call-by-value?
body: <p>I'm trying to figure out Perl subroutines and how they work.
  From <a href="http://perldoc.perl.org/perlsub.html" rel="noreferrer">perlsub</a> I understand that subroutines are call-by-reference and that an assignment (like <code>my(@copy) = @_;</code>) is needed to turn them into call-by-value.</p>
  
  <p>In the following, I see that <code>change</code> is called-by-reference because "a" and "b" are changed into "x" and "y". But I'm confused about why the array isn't extended with an extra element "z"?</p>
  
  <pre><code>use strict;
  use Data::Dumper;
  
  my @a = ( "a" ,"b" );
  
  change(@a);
  
  print Dumper(\@a);
  
  sub change
  {
      @_[0] = "x";
      @_[1] = "y";
      @_[2] = "z";
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$VAR1 = [
            'x',
            'y'
          ];
  </code></pre>
  
  <p>In the following, I pass a hash instead of an array. Why isn't the key changed from "a" to "x"?</p>
  
  <pre><code>use strict;
  use Data::Dumper;
  
  my %a = ( "a" =&gt; "b" );
  
  change(%a);
  
  print Dumper(\%a);
  
  sub change
  {
      @_[0] = "x";
      @_[1] = "y";
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$VAR1 = {
      'a' =&gt; 'y'
  };
  </code></pre>
  
  <p>I know the <em>real</em> solution is to pass the array or hash by reference using <code>\@</code>, but I'd like to understand the behaviour of these programs exactly.</p>