I have a script that uses DBI and DBD::Oracle. My sysadmin had some trouble getting DBD::Oracle to work, and in the end used a LD_LIBRARY_PATH=$ORACLE_HOME hack over which I have no control. The trouble is that DBD::Oracle is now compiled with this, and I can not run my script without setting that env var.

I plan to run the script in cron, and I know I can just do "env LD_LIBRARY_PATH=<path_to_oracle> my_script.pl." It works, I've tested it. We have other scripts that run that way now. But that just seems ugly to me. The script already has many configuration options set in a conf file, and it seems more elegant and consistent to set LD_LIBRARY_PATH in there. My shop also has standard modules for Oracle connections and config files that I'd like to use.

I've tried:

my $config; # scoped to script so I can continue to use it BEGIN { require Our::Config::Module; import Our::Config::Module; $config = new Our::Config::Module('filename') or die "Can't read config file\n"; $ENV{LD_LIBRARY_PATH} = $config->get('lib_path'); } use Our::Oracle::Module;

But this dies at compile time with the usual

"can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230. at /usr/lib/perl5/site_perl/5.8.5/Our/Oracle/Module.pm line 27 Compilation failed in require at /usr/lib/perl5/site_perl/5.8.5/Our/Oracle/Module.pm line 27."

that I always see when LD_LIBRARY_PATH is not set. So I'm assuming that's not an acceptable way to set env vars before use-ing modules that rely on them.

I strongly prefer to maintain portability by keeping machine specific stuff in a config file that I can modify without making code changes. Remember too that I have actual sysadmins, so I have no control over the Perl installation and don't want to maintain a separate one. With these restrictions, can anyone propose a clean way to set the env var that does not involve hard coding the path, either in the script or in the cron job? Or am I just letting an unaccountable fastidiousness lure me away from a perfectly good solution that I know works?


In reply to set env var at compile time by SantaClaus

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.