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
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|