Home: Perl Programming Help: Intermediate:
Environment Variables

New User

May 28, 2017, 7:02 AM

Views: 6602
Environment Variables


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

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.


May 28, 2017, 8:29 AM

Views: 6598
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,

Veteran / Moderator

May 28, 2017, 8:44 AM

Views: 6597
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

2) DBD::Oracle - Oracle database driver for the DBI module