Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

RE: my and its use

by autark (Friar)
on Nov 16, 2000 at 00:14 UTC ( [id://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.

Autark.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found