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


in reply to my and its use

| Can someone tell me where I am wrong in thinking that I can
| do my $dbh = DBI->connect($db, $user, $auth); ?

There is nothing wrong with your connect statement. However, in your code you are using the $dbh variable before it is properly defined.

my $dbh = DBI->connect($db, $user, $auth) || die $dbh->errstr;
Here you use the $dbh handle in the 'else' part of your statement. Think of it as this:
(my $dbh = DBI->connect($db, $user, $auth) ) || ( die $dbh->errstr );
So if the first part fails, it tries the second part, which happens to use the $dbh variable which failed to be defined because the connect call failed.

In this case I would put the 'my $dbh' part as a separate stament above the connect statment.

Autark.