http://www.perlmonks.org?node_id=1002338


in reply to use lib in cgi env

In a recent (FastCGI) application main-script, I once did this:

BEGIN { if (-f '/opt/location1/configuration.pm') { ## production environment: unshift( @INC, '/opt/location1/lib', '/opt/location1/scripts' ); } else { ## dev environment: unshift( @INC, '/opt/location2/lib', '/opt/location2/scripts', '/opt/location3/debug_lib' ); } }

The BEGIN block’s contents are executed before compilation begins, and therefore can be used to determine things such as library locations.   This example used the existence of a particular file in a particular location to decide where the libraries would be.   The use lib nomenclature was not used.

Developers relied upon setting the PERL5LIB environment variable to establish the library-location (appropriate to their particular machines), as the above mechanism would not have been invoked as they wrote and tested their code.

I’m not saying that this is the only way nor necessarily the best one.   But, it did work.