If you set up Oracle environment variables inside a script that loads the Oracle client libraries, you have to set up the variables before the libraries are loaded:
- You can set up %ENV in a BEGIN block, at least before loading DBD::Oracle implicitly via DBI->connect() or explicitly, better even before loading DBI.
- You can wrap your script in a shell script that sets the variables before passing control to your script via exec.
- You can add PassEnv or SetEnv directives to the Apache configuration.
I prefer the last way, so no script has to be modified and all scripts automatically get the right Oracle configuration.
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)