title: How does the Perl 'use' syntax work?
body: <p>Sample code:</p>
  
  <blockquote>
    <p><code>m1.pm</code></p>
  </blockquote>
  
  <pre><code>my $a;
  my $b;
  sub init {
      $a = shift;
      $b = shift;
  }
  
  sub printab {
      print "a = -$a-\n";
      print "b = -$b-\n";
  }
  
  1;
  </code></pre>
  
  <blockquote>
    <p><code>m2.pm</code></p>
  </blockquote>
  
  <pre><code>my $a;
  my $b;
  sub init {
      $a = shift;
      $b = shift;
  }
  
  1;
  </code></pre>
  
  <blockquote>
    <p><code>test.pl</code></p>
  </blockquote>
  
  <pre><code>use strict;
  use warnings;
  
  use m1;
  use m2;
  
  init('hello', 'world');
  printab();
  </code></pre>
  
  <p>Run:</p>
  
  <pre><code>$ perl test.pl
  a = --
  b = --
  $
  </code></pre>
  
  <p>What happens is that the <code>init('hello', 'world')</code> call is mapped to <code>m2.pm</code> and initializes the variables (<code>$a</code> and <code>$b</code>) there.</p>
  
  <p>This kind of makes sense, but what I do not understand is why those values are not available in <code>test.pl</code>.</p>
  
  <ul>
  <li><p>Is there something fundamentally wrong that I am trying to do here? <strong>What is the correct way to use two modules with same named subroutines and variables?</strong></p></li>
  <li><p>How exactly does a Perl <code>use</code> work? It would help if someone could contrast it with C's <code>#include</code> directive.</p></li>
  </ul>