Mind some constructive style suggestions?

First, I'm leery of declaring all of your variables at the start. They're effectively global -- at least, shared among all subroutines. That gives you some of the same drawbacks as global variables, most notably that you can whack one somewhere and not notice it until you reach another part of the code.

Second, calling subroutines with the leading ampersand is almost always wrong. It's right in this case, but only because you're using prototypes. Since you do want to pass arguments to the subs, drop the prototypes, and you can get rid of the ampersand. I suggest avoiding prototypes unless you want to act like a built-in operator. In other words, most of the time, you don't need them.

Besides that, it's generally a lot clearer to use named arguments instead of accessing elements of @_ directly. The exception is when you want to make it very clear that you're modifying an argument in place.

Here's how I would have written things:

#!/usr/bin/perl -w use DBI; use strict; $ENV{"ORACLE_HOME"}="ORACLE_HOME=/oravl01/oracle/8.0.6/"; $ENV{"TWO_TASK"}="nxt1"; my $dbh = sqlConnect("alan1", "alan1"); unless ($dbh) { showSQLError( $DBI::errstr ); exit; } getRef( $dbh ); sqlDisconnect( $dbh ); sub sqlConnect { my ( $username, $password ) = @_; my $connectString = join '/', $username, $password; return DBI->connect('dbi:Oracle:',$connectString); } sub sqlDisconnect { my $dbh = shift; $dbh->disconnect; } sub getRef { my $dbh = shift; my $statement = "select OI_REFERENCE from OPEN_ISSUES order by OI_ +REFERENCE asc"; print "$statement\n"; my $sth = $dbh->prepare($statement) or showSQLError($dbh->errstr); $sth->execute or showSQLError($sth->errstr); print "\n#"; while(my ($oir) = $sth->fetchrow_array) { print "\n- $oir"; } print "\n#\n"; } sub showSQLError { print "<SCRIPT> alert('$_[0]');</SCRIPT>"; }

If you set the RaiseError attribute on the database handle, you can do away with showSQLError too.


In reply to Re: Perl : DBI and Oracle by chromatic
in thread Perl : DBI and Oracle by aennen

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.