Where to store global database connection parameters

Is there an agreement for storing database connection parameters and other global parameters in perl? similar to .NET.config files?

Background: I inherited a large perl-based application that has a bunch of cgi scripts and several background services, all of which have database hostnames, user names, and hardcoded passwords. I would like to find one safe place to store them, and also, if possible, stick to perl conventions. I have little experience with perl, and google does not seem to lead me to an agreement for this.

+2
source share
1 answer

This is what I have so far:

Create a file called config.pl . Place it in a place accessible to all scripts, reducing the resolution to the minimum minimum required to read all scripts.

According to this perlmonks manual :

Make the contents of config.pl a hash:

 dbserver => 'localhost', db => 'mydatabase', user => 'username', password => 'mysecretpassword', 

Then in each script:

 use strict; # The old way.... #my $dbh = DBI->connect("DBI:mysql:database=mydatabase;host=localhost", "username", "mysecretpassword"); # The new way my %config = do '/path/to/config.pl'; my $dbh = DBI->connect("DBI:mysql:database=".$config{db}.";host=".$config{dbserver}."", $config{user}, $config{password}); 
+6
source

All Articles