Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: DBI Style Inquiry

by muba (Priest)
on Jun 27, 2013 at 08:48 UTC ( #1040959=note: print w/ replies, xml ) Need Help??


in reply to DBI Style Inquiry

Fugly is subjective, of course. However, what do you think about this?

sub get_loc { chomp $_[0]; # Aligned the "or" clauses with the main expressions my $dbh = DBI->connect("DBI:mysql:tracker:12.34.56.78", 'myuser', 'mypas +sword') or die "Connect to database failed: $DBI::errstr\n"; my $sth = $dbh->prepare("SELECT location FROM servers WHERE name=? LIMIT + 1") or die "Couldn't prepare statement: $DBI::errstr\n"; $sth->execute($_[0]); # No point in assigning if you aren't going to use @loc anyway # return my @loc = $sth->fetchrow_array(); return $sth->fetchrow_array(); # This is dead code. Execution will jump out of the sub due to the + return statement above! # Put disconnect call and "or" clause on same line $sth->finish; $dbh->disconnect or die "Error disconnecting: $DBI::errstr\n"; # Aligned "}"-line with "sub get_loc {" line }


Comment on Re: DBI Style Inquiry
Download Code
Re^2: DBI Style Inquiry
by edict (Novice) on Jun 27, 2013 at 09:00 UTC
    Awesome, I appreciate you giving time to formatting as well as pointing out the superfluous code!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2015-07-03 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls