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

Hi revered Monks,

I have the following DBI error. Can you through some light on this...

use DBI; my $dbh = DBI->connect(["dbi:Oracle:ppp","pp1","pp2"]); $dbh->disconnect; print "Database connect success\n";
Error i am getting is Can't connect to data source ARRAY(0x4001396c), no database driver spe +cified and DBI_DSN env var not set at - line 2
-Prasanna.K

Replies are listed 'Best First'.
Re: DBI Error
by marto (Cardinal) on Mar 22, 2007 at 21:32 UTC
    You are not connecting properly, [] is for an array reference, not an array. Try something like:
    use strict; use warnings; use DBI; my $dbh = DBI->connect( 'dbi:Oracle:ppp','marto','martossecretpassword +') || die "Database connection not made: $DBI::errstr"; $dbh->disconnect();
    Check out the DBD::Oracle documentation for further examples.

    Martin
Re: DBI Error
by jettero (Monsignor) on Mar 22, 2007 at 21:28 UTC
    That's an easier fix than you might be thinking. In perl, [] is for array references and () is for arrays. See perlreftut for further info on the difference.

    Update: I was just reading through the perlreftut, since I link to it fairly often. That's a good read even if you're a avid perl nerd already.

    -Paul

Re: DBI Error
by Mr. Muskrat (Canon) on Mar 23, 2007 at 17:06 UTC
    jettero and marto have already given you the answer you need but I thought that I would comment on it more as an aside. In documentation, square braces are often used to annotate optional parameters.