http://qs321.pair.com?node_id=111329

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

hi all you noble men, i just try to read in some data from a config file with following code and try to connect to a mysql database, but i always get the error, script could not connect to database.
#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use HTML::Entities; my $db_config_file = "db.cfg"; my %db_config = (); open CONFIG, ("< $db_config_file") or die "Konnte Datenbank Konfigurat +ions Datei nicht &ouml;ffnen! $!"; my @config_pairs = <CONFIG>; close CONFIG; foreach (@config_pairs) { chomp $_; my ($key, $value) = split/:/, $_; $db_config{$key} = $value; } my $database = $db_config{'database'}; my $db_server = $db_config{'db_server'}; my $db_user = $db_config{'db_user'}; my $db_pass = $db_config{'db_pass'}; my $dbh = DBI->connect("dbi:mysql:$database:$db_server", "$db_user", " +$db_pass") or die "Konnte Datenbankverbindung nicht herstellen: $!";
if i read in the config file with the following code
#!/usr/bin/perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; use HTML::Entities; my $db_config_file = "db.cfg"; my %db_config = (); open CONFIG, ("< $db_config_file") or die "Konnte Datenbank Konfigurat +ions Datei nicht &ouml;ffnen! $!"; my @config_pairs = <CONFIG>; close CONFIG; foreach (@config_pairs) { chomp $_; my ($key, $value) = split/:/, $_; $db_config{$key} = $value; } my $database = $db_config{'database'}; my $db_server = $db_config{'db_server'}; my $db_user = $db_config{'db_user'}; my $db_pass = $db_config{'db_pass'}; my $query = new CGI; print $query->header(); print $query->start_html(); print $database . "<br>"; print $db_server . "<br>"; print $db_user . "<br>"; print $db_pass . "<br>"; print $query->end_html();
it prints out the correct values->
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>U +ntitled Document</title> </head><body>db29970540 <br>db07.puretec.de <br>p7397271 <br>8vskBBPH<br></body></html>
what is the error i do? update-> the config file looks like this:
database:xxxxxx db_server:yyy.yyyyy.yy db_user:xxxxxx db_pass:yyyyyy