I've tried a gazillion different ways of doing this, none with very much success. Surely, there must be a way, and surely there are people doing similar things out there...

Background: I maintain a set of CGI scripts which use a bunch of perl modules. Each module is kept in two different places -- production vs. development. The CGI scripts are also kept in two different places (prod vs. dev).

I want to do something like this:

if( index( $ENV{SCRIPT_NAME}, '/dev/' ) == -1 ) { use lib "/blah/perllib/"; } else { use lib "/blah/perldev/"; }

so that if the CGI script is being called from a DEV environment, it will load the DEV modules; if the script is called from a PROD environment, it will load the PROD modules. This way, my CGI scripts can be identical (even though they're kept in two separate directories).

The method above isn't working, however, presumably because the 'use' pragma is evaluated at compile time, before $ENV has a value.

What other tricks are there whereby I might accomplish what I'm after? Basically, I want my source files to load the appropriate modules depending on where they're located...

Any thoughts?

--christopher@barsuk.com


In reply to dynamically loading modules/maintaining dev v. prod modules by christopherbarsuk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.