Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

RE: my and its use

by autark (Friar)
on Nov 16, 2000 at 00:14 UTC ( #41859=note: print w/replies, xml ) Need Help??

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://41859]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2020-11-30 05:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found