in reply to (tye)Re: programatically setting the LD_LIBRARY_PATH
in thread programatically setting the LD_LIBRARY_PATH

This is an old thread, but I've often had reason to refer back to it. Hopefully someone will also find the following useful.

Tye's solution works perfectly. It seems to be the best solution for cron jobs on a server with a diverse environment. The only problem is the the BEGIN block sort of breaks the use of perl -c and perl -d. If I understand correctly, it's because those options sort of wrap the existing code in code that will just compile or debug the existing code.

The following works, but only if the environment variables don't need to be set before the modules are loaded. Naturally, on a Windows system you will need to find an alternative method of determining an interactive shell...

my $interactive = TRUE if ( ! system( 'tty -s' ) / 256 ); unless ($interactive) { unless ( $ENV{BEGIN_BLOCK} ) { $ENV{"ORACLE_HOME"} = '/opt/oracle/product/9.2.0'; $ENV{"LD_LIBRARY_PATH"} = '/opt/oracle/product/9.2.0/lib'; $ENV{BEGIN_BLOCK} = 1; exec 'env',$0,@ARGV; } }

Credit for this goes to one of my (non-perlmonk) co-workers. I'm just taking the credit :D I've been using a variation of Tye's code until now.

-- GhodMode