Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am running an application on Apache. Currently I have set oracle home globablly through Apache. I would like to set it through perl, but I do not want to add it to the top of each script. How can I set it once for the entire app. I am still very much a newbie so please accept my apology for my ignorance. Any help is appreaciated.
  • Comment on setting oracle home globally through perl

Replies are listed 'Best First'.
Re: setting oracle home globally through perl
by blue_cowdawg (Monsignor) on Jul 08, 2003 at 18:35 UTC

    One of the ways that I have solved this and issues like it in the past has been to create a DBConfig.pm file somewhere in the list of directories pointed to by @INC.

    A sample sniglet looks like:

    package DBConfig;
    
    sub new {
               $self = { 
                         ORACLE_HOME => '/home/oracle',
                         SYBASE_HOME => '/home/sybase',
                         DBParms=>{
                           oracle => {
                             host => 'oraclehost',
                             user => 'user',
                             password => 'secret'
                            }
                
               };
        bless $self;
        return $self;
    }
    
    <snip!>
    
    

    To instantiate the information:

    use DBConfig;
    use DBI;
    
    my $dbconf=new DBConfig;
    #
    # Some hand waving here...
    my $dbh=DBI->connect(
                           $dbconf->{DBParms}->{oracle}->{user}
                   ...etc....
    

    You get the idea I hope.

    Now if the database information changes OR you add a supported database you just have to edit one place.

    A very cute extension to this idea that I saw recently was to read in the $ORACLE_HOME/network/admin/tnsnames.ora file and parse it to get data for individual application databases

    Hope this helps.


    Peter L. BergholdBrewer of Belgian Ales
    Peter@Berghold.Netwww.berghold.net
    Unix Professional
Re: setting oracle home globally through perl
by derby (Abbot) on Jul 08, 2003 at 17:48 UTC
    I think setting it in apache is the easiest route You could refactor all your apps' environment (or other global) variables into one module and then source that at the beginning of each script. There are advantages and disadvantages to both approaches. Can you further explain why you prefer setting it via perl instead of apache?

    Here's my stab at trying to figure out the best approach.

      Advantage Disadvantage
    Via Perl no need for apache admin access,
    ability to change on the fly,
    no need to stop/start apache on changes
    annoying code to keep track of meta data - especially if it never changes
    Via Apache Set it once and forget it,
    nothing special to do in code,
    meta data stays separated from code
    Need to stop/start apache when it changes,
    gives devs a "how the heck does that work" headache if unaware of apache conf settings

    -derby

Re: setting oracle home globally through perl
by LameNerd (Hermit) on Jul 08, 2003 at 19:00 UTC
    I have taken care of these types of site specific problems
    by using autoconf. I believe perl configure might be a good (or better) solution
    But I am not that familiar with it. Here's a quick start on autoconf. Autoconf has a lot of documentation.
    LameNerd@maxtrix6 ~/scripts_IN/conf_test $ ls -l total 2 -rwxrwxrwx 1 LameNerd None 320 Jul 8 11:47 configure. +ac -rwxrwxrwx 1 LameNerd None 231 Jul 8 11:48 test.in LameNerd@maxtrix6 ~/scripts_IN/conf_test $ cat configure.ac AC_INIT( test, 1.0 ) dnl AC_DEFUN([AC_ORACLE_HOME],[dnl AC_MSG_CHECKING(Checking for oracle home) if test -z "$ORACLE_HOME"; then AC_ERROR(No oracle home env var) else AC_MSG_RESULT(ok) AC_SUBST( ORACLE_HOME, "$ORACLE_HOME" ) fi ])dnl dnl AC_ORACLE_HOME( ORACLE_HOME ) AC_OUTPUT( [ test] ) LameNerd@maxtrix6 ~/scripts_IN/conf_test $ cat test.in #!/bin/sh #################################################### ### This script is intended as a example of how to ### use autoconf to determine ORACLE_HOME. #################################################### @ORACLE_HOME@ LameNerd@maxtrix6 ~/scripts_IN/conf_test $ autoconf LameNerd@maxtrix6 ~/scripts_IN/conf_test $ ls -l total 65 drwxr-xr-x+ 2 LameNerd None 0 Jul 8 11:48 autom4te.c +ache -rwxrwxrwx 1 LameNerd None 64409 Jul 8 11:48 configure -rwxrwxrwx 1 LameNerd None 320 Jul 8 11:47 configure. +ac -rwxrwxrwx 1 LameNerd None 231 Jul 8 11:48 test.in LameNerd@maxtrix6 ~/scripts_IN/conf_test $ ./configure checking Checking for oracle home... ok configure: creating ./config.status config.status: creating test LameNerd@maxtrix6 ~/scripts_IN/conf_test $ ls -l total 90 drwxr-xr-x+ 2 LameNerd None 0 Jul 8 11:48 autom4te.c +ache -rw-rw-rw- 1 LameNerd None 3630 Jul 8 11:49 config.log -rwxrwxrwx 1 LameNerd None 19840 Jul 8 11:48 config.sta +tus -rwxrwxrwx 1 LameNerd None 64409 Jul 8 11:48 configure -rwxrwxrwx 1 LameNerd None 320 Jul 8 11:47 configure. +ac -rw-rw-rw- 1 LameNerd None 227 Jul 8 11:49 test -rwxrwxrwx 1 LameNerd None 231 Jul 8 11:48 test.in LameNerd@maxtrix6 ~/scripts_IN/conf_test $ cat test #!/bin/sh #################################################### ### This script is intended as a example of how to ### use autoconf to determine ORACLE_HOME. #################################################### d:\Oracle\Ora81 LameNerd@maxtrix6 ~/scripts_IN/conf_test $