{"id":106,"date":"2012-08-22T21:11:38","date_gmt":"2012-08-22T13:11:38","guid":{"rendered":"http:\/\/www.hzaumycology.com\/chenlianfu_blog\/?p=106"},"modified":"2012-08-23T00:34:36","modified_gmt":"2012-08-22T16:34:36","slug":"configuring_inc_of_perl","status":"publish","type":"post","link":"http:\/\/www.chenlianfu.com\/?p=106","title":{"rendered":"Configuring_@INC_of_perl"},"content":{"rendered":"<p>Perl uses by default the array @INC as include path when searching for modules to load. This path is compiled into the perl binary when building it from source and can be printed by running perl -V, which will show something like:<\/p>\n<pre>$ perl -V\r\n...\r\nCompiled at Jun 22 2012 13:27:28\r\n@INC:\r\n\u00a0\u00a0\u00a0 \/usr\/local\/lib64\/perl5\r\n\u00a0\u00a0\u00a0 \/usr\/local\/share\/perl5\r\n\u00a0\u00a0\u00a0 \/usr\/lib64\/perl5\/vendor_perl\r\n\u00a0\u00a0\u00a0 \/usr\/share\/perl5\/vendor_perl\r\n\u00a0\u00a0\u00a0 \/usr\/lib64\/perl5\r\n\u00a0\u00a0\u00a0 \/usr\/share\/perl5<\/pre>\n<h1>1. Using the module lib<\/h1>\n<p>The standard module lib can be used to specify an explicit path to include. It must be stated at the top of the script:<\/p>\n<pre>#!\/usr\/bin\/perl\r\n#\r\nuse lib \"\/opt\/special\/plib\";\r\nuse strict;\r\nuse warnings;\r\n..<\/pre>\n<h1>2. Using the switch \u00adI at the command line<\/h1>\n<p>The switch \u00adI can be used to specify additional library locations when invoking the interpreter.<\/p>\n<pre>perl -I \/opt\/special\/plib script.pl<\/pre>\n<h1>3. Using the switch \u00adI in the first line of the script<\/h1>\n<p>The same \u00adI switch can be added to the interpreter specification.<\/p>\n<pre>#!\/usr\/bin\/perl -I \/opt\/special\/plib\r\n#\r\nuse strict;\r\nuse warnings;\r\n..<\/pre>\n<h1>4. Manipulating @INC directly<\/h1>\n<p>The array @INC can be manipulated directly using array operations<\/p>\n<pre>#!\/usr\/bin\/perl\r\n#\r\nBEGIN {\r\nunshift(@INC, \"\/opt\/special\/plib\");\r\n}\r\nuse strict;\r\nuse warnings;<\/pre>\n<p>This is the same as using the module lib, which in fact does something like this.<\/p>\n<h1>5. Using the environment variable PERL5LIB<\/h1>\n<p>The environment variable PERL5LIB can be used to specify additional include directories when running a perl script.<\/p>\n<pre>&gt; export PERL5LIB=\/opt\/special\/plib  #Adding this sequnce to \r\n\/etc\/profile, then the @INC would be changed persistently.\r\n&gt; \/path\/to\/script.pl<\/pre>\n<h1>6. Changing @INC at compile time<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Perl uses by default the array @INC as i &hellip; <a href=\"http:\/\/www.chenlianfu.com\/?p=106\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[9],"_links":{"self":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/106"}],"collection":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=106"}],"version-history":[{"count":4,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":167,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=\/wp\/v2\/posts\/106\/revisions\/167"}],"wp:attachment":[{"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chenlianfu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}