Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: sql-o-matic

by ambrus (Abbot)
on Sep 16, 2008 at 14:26 UTC ( [id://711701]=note: print w/replies, xml ) Need Help??


in reply to Re: sql-o-matic
in thread sql-o-matic

my $dbh=DBI->connect($dsn,$opts{user}{value},$opts{password}{value +}) || die($!);
The || operator has higher precedence than the = operator so you should either enclose the assignment in parentheses or use the lower precedence or operator.

Wrong. As die($!) never returns, it doesn't matter which way you write it.

Replies are listed 'Best First'.
Re^3: sql-o-matic
by massa (Hermit) on Sep 16, 2008 at 16:26 UTC
    Sorry but, even if your phrase holds a truth value, you are wrong in many levels.
    1. die can be overriden in one way or another, and start returning something!
    2. my $c = 'shat'; eval { $c = DBI->connect(xxx) || die } keeps the old value in $c (instead of putting undef there, like or would do), and this may not be what the user wants...
    3. it would be nice if people grew accostumed not to mix = and || inadvertently.
    So, my $c = DBI->connect(xxx) or die is the right idiom for good reasons.
    []s, HTH, Massa (κς,πμ,πλ)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-03-29 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found