{"id":192,"date":"2011-04-11T13:07:51","date_gmt":"2011-04-11T18:07:51","guid":{"rendered":"http:\/\/www.popmartian.com\/tipsntricks\/?p=192"},"modified":"2011-04-11T13:09:27","modified_gmt":"2011-04-11T18:09:27","slug":"how-to-pass-perl-library-paths-from-the-environment","status":"publish","type":"post","link":"https:\/\/www.popmartian.com\/tipsntricks\/2011\/04\/11\/how-to-pass-perl-library-paths-from-the-environment\/","title":{"rendered":"How To Pass PERL Library Paths From The Environment"},"content":{"rendered":"<p>You can have PERL look in different places for libraries and modules using a number of methods.  If you find yourself using a custom PERL module repository, you can make sure your PERL programs always reference it without touching the code.<\/p>\n<p>What we&#8217;re doing in a nutshell is telling PERL to push values on to the @INC array before loading any modules.  You can do this on the command line, in your PERL code or with the environment variable <code>PERL5LIB<\/code>.<\/p>\n<p><code>PERL5LIB<\/code> can contain more than one value.  Just set it in you .bashrc file or wherever you see fit.  This method works in bash:<\/p>\n<p><code>export PERL5LIB=\/first\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<br \/>\nexport PERL5LIB=\/second\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<br \/>\nexport PERL5LIB=\/third\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<\/code><\/p>\n<p>You can check what PERL is going to use by printing out the contents of @INC.  <a href=\"http:\/\/www.popmartian.com\/tipsntricks\/2009\/02\/06\/perl-how-to-print-a-list-without-a-loop\/\">You can print an array without a loop using join() as I blogged about before<\/a>:<\/p>\n<p><code>perl -e 'print join \"\\n\", @INC;'<\/code><\/p>\n<p>Let&#8217;s put it together:<br \/>\n~$ <code>perl -e 'print join \"\\n\", @INC;'<\/code><br \/>\n<em>\/etc\/perl<br \/>\n\/usr\/local\/lib\/perl\/5.10.0<br \/>\n\/usr\/local\/share\/perl\/5.10.0<br \/>\n\/usr\/lib\/perl5<br \/>\n\/usr\/share\/perl5<br \/>\n\/usr\/lib\/perl\/5.10<br \/>\n\/usr\/share\/perl\/5.10<br \/>\n\/usr\/local\/lib\/site_perl<br \/>\n.<\/em><\/p>\n<p>~$ <code>env|grep -i perl<\/code><br \/>\n~$<\/p>\n<p>~$ <code>export PERL5LIB=\/first\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<\/code><br \/>\n~$ <code>export PERL5LIB=\/second\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<\/code><br \/>\n~$ <code>export PERL5LIB=\/third\/path\/to\/libs\"${PERL5LIB:+:$PERL5LIB}\"<\/code><\/p>\n<p>~$ <code>env|grep -i perl<\/code><br \/>\n<em>PERL5LIB=\/third\/path\/to\/libs:\/second\/path\/to\/libs:\/first\/path\/to\/libs<\/em><\/p>\n<p>~$ <code>perl -e 'print join \"\\n\", @INC;'<\/code><br \/>\n<em>\/third\/path\/to\/libs<br \/>\n\/second\/path\/to\/libs<br \/>\n\/first\/path\/to\/libs<br \/>\n\/etc\/perl<br \/>\n\/usr\/local\/lib\/perl\/5.10.0<br \/>\n\/usr\/local\/share\/perl\/5.10.0<br \/>\n\/usr\/lib\/perl5<br \/>\n\/usr\/share\/perl5<br \/>\n\/usr\/lib\/perl\/5.10<br \/>\n\/usr\/share\/perl\/5.10<br \/>\n\/usr\/local\/lib\/site_perl<br \/>\n.<\/em><\/p>\n<p>And there it is.  Your PERL apps will look in those locations starting from the top.<\/p>\n<blockquote><p>Did you find this post useful or have questions or comments?  Please let  me know!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>You can have PERL look in different places for libraries and modules using a number of methods. If you find yourself using a custom PERL module repository, you can make sure your PERL programs always reference it without touching the &hellip; <a href=\"https:\/\/www.popmartian.com\/tipsntricks\/2011\/04\/11\/how-to-pass-perl-library-paths-from-the-environment\/\">Continue reading <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":{"footnotes":""},"categories":[3,12,9],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","hentry","category-how-to-do-stuff","category-perl","category-programming"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/comments?post=192"}],"version-history":[{"count":6,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":235,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/192\/revisions\/235"}],"wp:attachment":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/media?parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/categories?post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/tags?post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}