I think changes to SHLIB_PATH (like LD_LIBRARY_PATH) don't affect the running process. Someone posted an example some weeks ago that sets the end var then re-executes the script - that would work.
It helps if you remember that perl is the running process that has to load shared libraries, not the Perl script. As a result, changes to environment variables in the script don't necessarily help the loader running for perl find the Oracle shared libraries.
I either set all my environment variables before starting Perl, or set them in the script and then have it exec() itself. In some OSes setting them in a BEGIN block may work, YMMV.
To expand slightly with details for Solaris as a specific example (Linux is similar): perl XS libraries (such as DBI and DBD::Oracle) consist of a shared object which is pulled in at run-time via dlopen(), which in turn is an entry point into the run-time linker (ld.so.1). When you build DBD::Oracle, the linker establishes a dependency between the Oracle.so you generate when you build DBD::Oracle and the appropriate Oracle library (libclntsh): we can examine this by using 'ldd' and 'dump -Lv' on Oracle.so:
lbclntsh.so.9.0 => /home4/oracle/product/9.2.0/lib/libclntsh.so.9.0
[1] NEEDED libclntsh.so.9.0 [14] RUNPATH /home4/oracle/product/9.2.0/lib
Now if you move Oracle, the RUNPATH in the perl Oracle.so points to the wrong place. Note that perl will probably be able to find Oracle.so file OK, the failure is usually reported as an unresolved symbol in Oracle.so because the linker can no longer find libclntsh.
If you set LD_LIBRARY_PATH its value is added to the front of the RUNPATH stored in any shared objects that are loaded However ld.so.1 only looks at the value of LD_LIBRARY_PATH at process startup, and ld.so.1 actually runs *before* the main() of your program - in this case the main() of the perl interpreter. For this reason, setting LD_LIBRARY_PATH inside your perl script will have no effect, as it will happen *after* ld.so.1 has already read the value. If however the script sets LD_LIBRARY_PATH and then re-execs itself, when ld.so.1 runs again it will see the value of LD_LIBRARY_PATH in the environment and act accordingly.
-- Alan Burlison --
