DBI things: 1. Check out the database handle attributes RaiseError, PrintError, and AutoCommit. For error checking(and catching) your DBI statements, especially in CGI scripts where you may not want to die(you might want to give a nice Error screen) when you have a bad problem, you can't beat RaiseError and "eval". 2. Get into the habit of using placeholders(?) - although they won't really buy you much here, you're bound to run into a situation where they will help with quoting issues and/or performance. Is use them *all* the time. 3. while (@_ = $sth->fetchrow_array()) { $emp_id = $_[0]; $emp_name = $_[1]; $dept = $_[2]; can be written to be more easily understandable this way: while (($emp_id, $emp_name, $dept) = $sth->fetchrow_array()) { no sense using array subscripts when it's not necessary. You might also have a look at fetchrow_hashref.

I'm also going to throw this one out there, just in case you're not familiar with the excellent documentation that comes with Perl - I worked for quite a few years with Perl myself before someone clued me in. If you're not familiar with the "perldocs", start by doing "perldoc perldoc" at a command prompt. You can see the perldocs for most any Perl module by doing "perldoc module name" at a command prompt. For example, to view the DBI perldocs, do "perldoc DBI".

My appologies if you already knew about this stuff.

HTH.

In reply to Re: A Matter of Style in CGI by hmerrill
in thread A Matter of Style in CGI by Spenser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.