I have used code like this:
use DBI;
use Env;
use strict;
# Make sure that the environmental variables are undefined.
#
undef $ENV{ORA_SID};
undef $ENV{ORACLE_SID};
#
# Defing the environmental variables.
#
$ENV{ORA_SID} ='test';
$ENV{ORACLE_SID} =$ENV{ORA_SID};
I have had no issues connecting to my databases using this code.
HTH
Sam Gold
-----Original Message-----
From: Wolf, Dr. Stefan [mailto:[EMAIL PROTECTED]
Sent: Friday, June 06, 2003 8:43 AM
To: '[EMAIL PROTECTED]'
Subject: how to define env variables in perl script?
Hi,
i have a oracle database in a clustered environment (mc/sg on hpux) with
locally installed oracle driver. To connect to a database, i have to set and
export variables (mainly SHLIB_PATH to point to the local libraries) in a
shell script, then call the perl script. When i try setting the env
variables inside a begin block, this seems to work, variables are set
correctly. But the database connection fails! Probably the oracle driver is
loaded befor the begin block is compiled and run. Any suggestions how to
solve this? Some lines from the script are shown below.
Regards,
S. Wolf
BEGIN
{
$ENV{'ORACLE_BASE'}="/oracle/CLIENT" unless $ENV{'ORACLE_BASE'};
$ENV{'ORACLE_HOME'}="$ENV{'ORACLE_BASE'}/product/8.1.7" unless
$ENV{'ORACLE_HOME'};
$ENV{'SHLIB_PATH'}="$ENV{'ORACLE_HOME'}/lib" unless $ENV{'SHLIB_PATH'};
}
use strict;
use DBI;
.........
# establish database handler, connect to database
my $dbh = DBI->connect("DBI:Oracle:$dbname", $dbuser, $dbpassword)
|| die "Unable to connect to $dbname:
$DBI::errstr\n";