title: Global variable resetting itself in subroutine
body: <p>Forgive me for the (probably) stupid question, but I'm messing around with this code (actually a model of something in a larger program), and something is throwing me off:</p>
  
  <pre><code>sub recurse { 
    my $m = shift; 
    $g .= "::" . $m; 
    if ($m == 0) { return $g; } 
    else { $m--; recurse ($m); }
  }
  
  for ($i = 0; $i &lt; 3; $i++)
  {
    my $g = '';
    $str = recurse (10); 
    print $str . "\n";
  }
  </code></pre>
  
  <p>The first iteration of the 'for' loop works fine.  On subsequent iterations, however, I am having an issue.  As you can see, the global variable $g is reset first thing in the 'for' loop before the recursive function is called.  With the debugger, I can see that $g is set back to '' before the function is called.  However, as soon as the function 'recurse' is entered, it goes back to the previous value.  What am I missing here?</p>
  
  <p>As a corollary, I don't like using a global variable here.  What is the 'correct' way to do it without making $g a parameter for recurse()?</p>