There are as many ways of skinning that cat as there are folks trying to skin it. Here are some of the aproaches I've seen without passing judgement on any of them.

Environmental values

As you pointed out you an always use your environmental values to drive your application's behavior. You showed one way, but here's an alternative:
# .bashrc sniglet export DBHOST="mytestdbhost.mydomain.tld" export DBDB="mytestdb" export DBUSER="user" export DBPASSWORD="SeCrEt" export DBDRIVER="mysql" ------- 8<snip! 8<-------------------------- # in some perl code, far far away use DBI; my $dbhost = $ENV{'DBHOST'}; my $dbname = $ENV{'DBDB'}; my $dbuser = $ENV{'DBUSER'}; my $dbpassword = $ENV{'DBPASSWORD'}; my $dbdriver = $ENV{'DBDRIVER'}; my $DSN=sprintf("DBI:%s:host=%s:database=%s", $dbdriver,$dbhost,$dbnaem); my $dbh=DBI->connect($DSN,$dbuser,$dbpassword) or die DBI->errstr; ... etc....
The above ripped from some code I'm maintaining. The actual values changed to protect the guilty.

Configuration Files

There are two general methods I've seen for doing this. One uses an external configuration file that you either parse yourself or you can use one of several AppConfig family of CPAN modules to do your dirty work.

The other method I've seen (and used myself) is to create your own module that encapsulates your database access configuration. The one I use over and over again I call (oddly enough) DbConfig.

use DBConfig; use DBI; my $dbh=DBI->connect(DBConfig::DSH,DBConfig::User,DBConfig::Password) +or die $DBI::errstr;

When I install DBConfig on my production boxes I make the appropriate changes to the module. Otherwise the code is identical.

As always in Perl TIMTOWTDI!


Peter L. Berghold -- Unix Professional
Peter at Berghold dot Net
   Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

In reply to Re: Testing & Databases by blue_cowdawg
in thread Testing & Databases by domm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.