title: Need help understanding portion of script (globs and references)
body: <p>I was reviewing <a href="https://stackoverflow.com/questions/8250505/capture-variable-assignments-in-a-perl-eval">this question</a>, esp the <a href="https://stackoverflow.com/a/8251118/2534803">response</a> from Mr Eric Strom, and had a question regarding a portion of the more "magical" element within. Please review the linked question for the context as I'm only trying to understand the inner portion of this block:</p>
  
  <pre><code>for (qw($SCALAR @ARRAY %HASH)) {
      my ($sigil, $type) = /(.)(.+)/;
      if (my $ref = *$glob{$type}) {
          $vars{$sigil.$name} = /\$/ ? $$ref : $ref
      }
  }
  </code></pre>
  
  <p>So, it loops over three words, breaking each into two vars, <code>$sigil</code> and <code>$type</code>.  The <code>if {}</code> block is what I am not understanding.  I suspect the portion inside the <code>( .. )</code> is getting a symbolic reference to the content within <code>$glob{$type}</code>... there must be some "magic" (some esoteric element of the underlying mechanism that I don't yet understand) relied upon there to determine the type of the "pointed-to" data?</p>
  
  <p>The next line is also partly baffling.  Appears to me that we are assigning to the vars hash, but what is the rhs doing?  We did not assign to <code>$_</code> in the last operation (<code>$ref</code> was assigned), so what is being compared to in the <code>/\$/</code> block?  My guess is that, if we are dealing with a scalar (though I fail to discern how we are), we deref the <code>$ref</code> var and store it directly in the hash, otherwise, we store the reference.</p>
  
  <p>So, just looking for a little tale of what is going on in these three lines.  Many thanks!</p>