title: How to use $a and $b in Perl subroutine
body: <p>I would like to use <code>$a</code> and <code>$b</code> variables in my anonimous binary functions like it is done in <code>sort {$a &lt;=&gt; $b} (1, 2, 3)</code> but I can not figure out why code like </p>
  
  <pre><code>#!/usr/bin/env perl
  use strict;
  use warnings;
  
  Foo::Bar(sub { $a + $b });
  
  package Foo;
  sub Bar {
      my ($function) = @_; 
  
      for my $i (1, 2, 3) {
          local ($a, $b) = ($i, $i);
          print $function-&gt;() . "\n";
      }
  }    
  </code></pre>
  
  <p>does not work. While </p>
  
  <pre><code>#!/usr/bin/env perl
  use strict;
  use warnings;
  
  Foo::Bar(sub { $_ });
  
  package Foo;
  sub Bar {
      my ($function) = @_; 
  
      for my $i (1, 2, 3) {
          local $_ = $i;
          print $function-&gt;() . "\n";
      }
  }
  </code></pre>
  
  <p>works fine.</p>
  
  <p>What am I doing wrong?</p>