title: How does @_ work in Perl subroutines?
body: <p>I was always sure that if I pass a Perl subroutine a simple scalar, it can never change its value outside the subroutine. That is:</p>
  
  <pre><code>my $x = 100;
  foo($x);
  # without knowing anything about foo(), I'm sure $x still == 100
  </code></pre>
  
  <p>So if I want <code>foo()</code> to change <code>x</code>, I must pass it a reference to <code>x</code>.</p>
  
  <p>Then I found out this is not the case:</p>
  
  <pre><code>sub foo {
   $_[0] = 'CHANGED!';
  }
  my $x = 100;
  foo($x);
  print $x, "\n"; # prints 'CHANGED!'
  </code></pre>
  
  <p>And the same goes for array elements:</p>
  
  <pre><code>my @arr = (1,2,3);
  print $arr[0], "\n"; # prints '1'
  foo($arr[0]);
  print $arr[0], "\n"; # prints 'CHANGED!'
  </code></pre>
  
  <p>That kinda surprised me. How does this work? Isn't the subroutine only gets the <strong>value</strong> of the argument? How does it know its address?</p>