Home: Perl Programming Help: Intermediate:
Environment Variables



yakirllc
New User

May 28, 2017, 7:02 AM


Views: 2800
Environment Variables

Hi,

Is there a way to set new environment varaibles using perl?
Using the $ENV is not good enough.
Example:

Code
$ENV{"ORACLE_SID"}="test"; 
print `echo \$ORACLE_SID`;

Will return an empty string.
Which means, the ORACLE_SID variable wasn't set in the system.
The reason I need a way to make it work is because I need to be able to run an Oracle query using sqlplus, and I'm not allowed to use the tnsnames.ora(which will allow me to use the username@InstanceName convention).
So my only option is to set the ORACLE_SID variable and then use the sqlplus as follows:
sqlplus -S user/passwd @"queryFileName.sql"

Thanks for the help.


BillKSmith
Veteran

May 28, 2017, 8:29 AM


Views: 2796
Re: [yakirllc] Environment Variables

No, you cannot do this. The reason has nothing to do with perl. Environmental variables only pass information to lower level programs. They cannot return information to any other program. I believe that this is true on all operating systems.
Good Luck,
Bill


FishMonger
Veteran / Moderator

May 28, 2017, 8:44 AM


Views: 2795
Re: [yakirllc] Environment Variables

If you're needing to connect to oracle from within the perl script then use the capabilities that perl provides instead of shelling out to sqlplus.

You need 2 perl modules.
1) DBI - Database independent interface for Perl
https://metacpan.org/pod/DBI

2) DBD::Oracle - Oracle database driver for the DBI module
https://metacpan.org/pod/DBD::Oracle