title: Perl map block local variable usage
body: <p>This code compiles a set by way of hash keys of the unique basename stubs in a set of paths.</p>
  
  <pre><code>%stubs = map { $f=basename $_; $f =~ /^([A-Za-z]+[0-9]+)\./ ; $1=&gt;() } @pathlist;
  </code></pre>
  
  <p>Why do I need the <code>$f</code> references here? I thought I'd be ok with:</p>
  
  <pre><code>%stubs = map { basename; /^([A-Za-z]+[0-9]+)\./; $1=&gt;() } @pathlist;
  </code></pre>
  
  <p>But I get no match. Am I not permitted to modify $_ in the map block?</p>
  
  <p><br /><br />
  For those wondering what the code is doing:</p>
  
  <p>For each $path (@pathlist), it's getting the basename, matching the first letter-number sequence, and then returning the first bracket match as the key on an empty list value. Example:</p>
  
  <pre><code>/some/dir/foo123.adfjijoijb
  /some/dir/foo123.oibhobihe
  /some/dir/bar789.popjpoj
  </code></pre>
  
  <p>returns</p>
  
  <pre><code>foo123 =&gt; ()
  bar789 =&gt; ()
  </code></pre>
  
  <p>After which I use the keys of the map as the set of values so process. </p>