Gurus - In keeping with a good Perl programming style, is it better to have two ODBC connections to different databases declared twice? Or, is it better to have one declaration put in an array or hash that will loop through? I'm launch a sciprt that will check the status of two databases, see the below code.
#!/usr/bin/perl -w use strict; use Win32::ODBC; my $DSN = "DSN=DATABASE1;UID=sa;PWD=password;"; my $connection = new Win32::ODBC("$DSN"); if (!$connection){die "Could not open connection to DSN because of [$! +]";} my $SQL = "SELECT Field1, Field2 FROM table1"; if ($connection->Sql($SQL)) { print "SQL failed.\n"; print "Error: " . $connection->Error() . "\n"; print $connection->Error() . "\n"; $connection->Close(); die;} #Report header. print "Field 1" . "\t\t\t" . "Field 2" . "\n"; while ($connection->FetchRow()) { my %dataRow =$connection->DataHash(); print $dataRow{field1} . "\t\t" . $dataRow{field2} . "\n";} $connection->Close(); my $DSN2 = "DSN=DATABASE2;UID=sa;PWD=password;"; my $connection2 = new Win32::ODBC("$DSN"); if (!$connection2){die "Could not open connection to DSN because of [$ +!]";} my $SQL2 = "SELECT * FROM TABLE2"; if ($connection2->Sql($SQL2)) { print "SQL failed.\n"; print "Error: " . $connection->Error() . "\n"; print $connection->Error() . "\n"; $connection->Close(); die;} while ($connection2->FetchRow()) { my %dataRow2 =$connection2->DataHash(); print $dataRow2{field1} . "\t\t" . $dataRow2{field2} . "\n";} $connection->Close();

In reply to Two ODBC Connections by drodinthe559

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.