The following section from the DBI pod suggests one alternative for isolating the target DB against which you will run, from the code itself, using environment vars.
As a convenience, if the $data_source parameter is undefined or empty, the DBI will substitute the value of the environment variable DBI_DSN. If just the driver_name part is empty (i.e., the $data_source prefix is "dbi::"), the environment variable DBI_DRIVER is used. If neither variable is set, then
connect dies.
Examples of $data_source values are:
dbi:DriverName:database_name
dbi:DriverName:database_name@hostname:port
dbi:DriverName:database=database_name;host=hostname;port=port
There is no standard for the text following the driver name. Each driver is
free to use whatever syntax it wants. The only requirement the DBI makes is
that all the information is supplied in a single string. You must consult the
documentation for the drivers you are using for a description of the syntax
they require. (Where a driver author needs to define a syntax for the
$data_source, it is recommended that they follow the ODBC style, shown in the
last example above.)
If the environment variable DBI_AUTOPROXY is defined (and the driver in
$data_source is not "Proxy") then the connect request will automatically be changed to:
$ENV{DBI_AUTOPROXY};dsn=$data_source
DBI_AUTOPROXY is typically set as "dbi:Proxy:hostname=...;port=...".
If $ENV{DBI_AUTOPROXY} doesn't begin with 'dbi:' then "dbi:Proxy:" will be
prepended to it first. See the DBD::Proxy documentation for more details.
If $username or $password are undefined (rather than just empty), then the DBI will substitute the values of the DBI_USER and DBI_PASS environment variables, respectively. The DBI will warn if the environment variables are not defined.
However, the everyday use of these environment variables is not recommended for
security reasons. The mechanism is primarily intended to simplify testing.
See below for alternative way to specify the username and password.
Edited by BazB - change to use blockquote and wrap code/variable sections only in code tags.