<?xml version="1.0" encoding="windows-1252"?>
<node id="238691" title="Conditional 'use lib'" created="2003-02-26 02:48:52" updated="2005-08-08 22:05:13">
<type id="115">
perlquestion</type>
<author id="125011">
bjdean</author>
<data>
<field name="doctext">
&lt;p&gt;Greetings folks,&lt;/p&gt;

&lt;p&gt;I've recently come across a problem whereby I'd like to conditionally use 'use lib' (which doesn't work due to the early order of processing 'use' in compilation).&lt;/p&gt;

&lt;p&gt;The question then, is there a better way then this:&lt;/p&gt;

&lt;pre&gt;
BEGIN {
    use Sys::Hostname;
    if ( hostname() eq 'foo.bar.org' ) {
        unshift @INC, ('/alternate/libdir');
    } else {
        unshift @INC, ('/default/libdir');
    }
}
&lt;/pre&gt;

&lt;p&gt;To achieve something close to to 'meaning' of:&lt;/p&gt;

&lt;pre&gt;
BEGIN {
    use Sys::Hostname;
    if ( hostname() eq 'foo1.bar.org' ) {
        use lib '/alternate/libdir';
    } else {
        use lib '/default/libdir';
    }
}
&lt;/pre&gt;</field>
</data>
</node>
