title: BEGIN blocks in Perl
body: <p>Searching the Internet, I get that the BEGIN block will get evaluated and executed in the compile phase. But can the @INC or other variables be inherited?</p>
  
  <p>Below is what I wrote for testing. The directory structure is as:</p>
  
  <pre><code>|-- alexpackages
  |   |-- alex1.pm
  |   `-- alex2.pm
  |-- foo.pl
  `-- main.pl
  </code></pre>
  
  <p>For each file:</p>
  
  <p>cat alexpackages/alex1.pm</p>
  
  <pre class="lang-perl prettyprint-override"><code>package alex1;
  
  sub foo()
  {
      print "this is alex1::foo\n";
  }
  
  1;
  </code></pre>
  
  <p>cat alexpackages/alex2.pm</p>
  
  <pre class="lang-perl prettyprint-override"><code>package alex2;
  
  sub foo2()
  {
      print "this is is alex2::foo2\n";
  }
  
  1;
  </code></pre>
  
  <p>cat foo.pl</p>
  
  <pre class="lang-perl prettyprint-override"><code>alex1::foo();
  </code></pre>
  
  <p>cat main.pl</p>
  
  <pre class="lang-perl prettyprint-override"><code>BEGIN
  {
      push(@INC, '~/programs/perl/alexpackages');
  }
  
  use strict;
  use warnings;
  
  use alex1;
  use alex2;
  
  #alex1::foo();           # 1. This works good
  system("perl foo.pl");   # 2. This fails
  </code></pre>
  
  <p>Just as what my program tells that the @INC does not work for a new system call. It seems to me that system call will not inherit the system environment. Am I right?</p>
  
  <p>And can how I make the environment variables to the following system call?</p>