title: Perl default variable $_
body: <p>I thought I understood map however the following has results that I don't understand. I know why it's happening I just don't know how it is happening. </p>
  
  <p>The problem is that the contents of @array are changing because <code>$_</code> is being reset during <code>_do_stuff_to_file</code> call. so what is printed is <code>here: \nhere:\n</code> when I expect it to be <code>here: donkie\nhere: kong\n</code>.</p>
  
  <p><strong>Note:</strong> This is not tested code. It's just what I remember seeing from lab. Why are the contents of <code>@array</code> changing?</p>
  
  <p>If I set <code>$_</code> to <code>$f</code> before returning 1 from <code>_some_func</code>. Then the array is still intact.</p>
  
  <p>Here is an example program to illustrate what I am seeing:</p>
  
  <pre><code>my @array = ("donkie", "kong");
  map { push @junk, _some_func('blah', $_); } @array;
  
  if (join ('', @junk) !~ /0/)
  {   # for example sake this is always true since return 1 from _some_func.
      print map { "here: $_\n"; } @array;
  }
  
  sub _some_func
  {   # for example sake, lets say $f always exists as a file.
      my $j = shift;
      my $f = shift;
      return 0 if !open(FILE, "&lt; $f");
      close FILE;
      _do_stuff_to_file($f);
  
      return 1;
  }
  
  
  sub _do_stuff_to_file
  {
      my $f = shift;
      open(IN, "&lt; $f");
      open(OUT, "&gt; $f.new");
  
      while (&lt;IN&gt;)
      {
          print OUT;
      }
  
      close IN;
      close OUT;
  }
  </code></pre>