Hi All,

I wanted to make a database connection using the values provided
in .cfg file

my.cfg
***********

dbname=xyz
user=abc
passwd=abc123

***********

my perl package which need to read the my.cfg file & make the
connection

mypackage
************
sub new(){
my @arr=();

        readcfg();

        #foreach  (@arr) {
        #print "$_ \n";
        #print "for loop";
        #}

       [EMAIL PROTECTED];
       $usr = @arr[1];
       $pwd ||= @arr[2];
#       ($self) = {};
#       bless($self);
       $databasehandle = DBI->connect("DBI:Pg:dbname=$dbname",$usr,
$pwd,{PrintError =>1});

       if (!$databasehandle){
               print "Database connection is not estabilished";
               exit;
       }



        sub readcfg {

               # $cfgpath = shift;
                open(FH,"<my.cfg")or die "Can't open file";
                while (my $line=<FH>) {
                        chomp $line;
                         next if ($line =~ /^\s*#/);
                         next if ($line =~ /^\s*$/);
                        $line =~ s/#.*$//;
                }

($Key,$Val) = ($line =~ /^\s*(\S+)\s*=\s*(.*\S)\s*$/);
                 push @arr,$Val;
                return @arr;
}

return($self);
}


---------

I am getting an error

(DBI:connect ' ' ) failed .Fatal database 'root' doesn't exist.

Can any one suggest me how can we read the values from conf file & get
the database connection .
& i need to call the database handle to call the subroutine.

Thanks in advance.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to