Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: sql-o-matic

by jwkrahn (Abbot)
on Sep 16, 2008 at 06:15 UTC ( [id://711613]=note: print w/replies, xml ) Need Help??


in reply to 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.

According to the DBI manual:

If the connect fails (see below), it returns "undef" and sets both $DBI::err and $DBI::errstr. (It does not explicitly set $!.) You should generally test the return status of "connect" and "print $DBI::errstr" if it has failed.

So that line should be:

my $dbh = DBI->connect( $dsn, $opts{ user }{ value }, $opts{ password +}{ value } ) or die $DBI::errstr;
crash_n_burn() if $cl_part=~/^-h$|^--help$|^-h$/i;

If the first  ^-h$ pattern doesn't match what makes you think that the second one will?

$s_insert=<<EOT; /* Insert SP for $table */ drop procedure if exists insert_$table; delimiter // create procedure insert_table ( EOT

Shouldn't that be:

$s_insert=<<EOT; /* Insert SP for $table */ drop procedure if exists insert_$table; delimiter // create procedure insert_$table ( EOT

Replies are listed 'Best First'.
Re^2: sql-o-matic
by ambrus (Abbot) on Sep 16, 2008 at 14:26 UTC
    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.

      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://711613]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found