title: How do I set Perl's @INC for a CGI script?
body: <p>I have the following, simplest Perl CGI script:</p>
  
  <pre><code>use strict;
  use warnings;
  use CGI();
  use CGI::Carp qw(fatalsToBrowser);
  
  use Template;
  
  print CGI::header();
  
  foreach(@INC) {
      print "$_\n";
  }
  </code></pre>
  
  <p>When called (<a href="http://[..]/cgi-bin/p.cgi" rel="nofollow noreferrer">http://[..]/cgi-bin/p.cgi</a>) I am given the following error:</p>
  
  <pre><code>Can't locate Template.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /home/pistacchio/webapps/htdocs/cgi-bin/p.cgi line 8.
  BEGIN failed--compilation aborted at /home/pistacchio/webapps/htdocs/cgi-bin/p.cgi line 8.
  </code></pre>
  
  <p>I made sure that Template is installed and indeed when running this program from shell it works (loads Template) and outputs:</p>
  
  <pre><code>Content-Type: text/html; charset=ISO-8859-1
  
  /home/pistacchio/lib/perl5
  /home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
  /home/pistacchio/lib/perl5/lib
  /home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/site_perl/5.8.8
  /usr/lib/perl5/site_perl
  /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/vendor_perl/5.8.8
  /usr/lib/perl5/vendor_perl
  /usr/lib/perl5/5.8.8/i386-linux-thread-multi
  /usr/lib/perl5/5.8.8
  </code></pre>
  
  <p>Template is installed in <code>/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi</code></p>
  
  <pre><code>[pistacchio@web118 i386-linux-thread-multi]$ pwd
  /home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
  [pistacchio@web118 i386-linux-thread-multi]$ ls
  auto  perllocal.pod  Template  Template.pm
  </code></pre>
  
  <p>This directory is correctly listed in <code>env</code> and, as previously posted, in <code>@INC</code>. In <code>@INC</code> it is shown twice, so I even tried to pop it out before calling <code>use Template</code>, but without result. From <code>env</code>:</p>
  
  <pre><code>[pistacchio@web118 i386-linux-thread-multi]$ env
  [..]
  PERL5LIB=/home/pistacchio/lib/perl5:/home/pistacchio/lib/perl5/lib:/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
  [..]
  </code></pre>
  
  <p>Removing <code>use Template</code> gets rid of the problem.</p>