My tip which seems small but is actually big is use eval blocks for error checking.
Here is an example which happens to use DBI. DBI implements tons to error checking which uses die if you ask it to.
$stmt="SELECT cnam_oficial FROM evocrs WHERE evocrs_id=?";
$sth->bind_columns( \( $cn ) );
# $dbh->commit; #if we were writing some records instead of readin
# $dbh->rollback; #if we were doing transactions and writing data
print STDERR "Could not retreive course name: $stmt: $@\n";
print "Could not retrieve course name\n";
I delclare $stmt in a scope where the eval and the error block can both see it for reporting.
The eval saves having to say or die "message" on every line of your code.
The RaiseError tells DBI to die on any database error.
I put the commit inside the eval as the last line because that will not be reached if there is any problem since a die will jump right out of the eval without doing the rest of the block.
The rollback goes in the $@ block which is executed if the eval fails.
This makes your code nice and clean and results in errors being trapped always.
The DBI module is very nice about this since RaiseError causes a die for all errors.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||