I saw what some other people have done and to a certain degree they are missing the point of encapsulation and design.
- You want a subroutine that prevents redundancy, excellent
- There is only one variable changed in the request
- There is only one variable changed from the result
- Keep your code focused, make it simple and do not do too many things at one time
sub get_rows_from {
my $dbh = shift;
my $table = shift;
$dbh->Sql ("SELECT * FROM " . $table);
my %result;
while ($dbh->FetchRow() ) {
my %x= $dbh->DataHash();
$result{ $x{ID} } = \%x;
}
return \%result;
}
my $config_data_ref = $dbh->get_rows_from( 'ConfigData' );
my $dicom_data_ref = $dbh->get_rows_from( 'DicomDestinations' );
So what we have a subroutine, with a simple interface. We only have to pass one thing to it (the table name). We will get back a hash reference. Since we are not doing data manipulation in the subroutine, we do not have to guess what the result will be if we passed a hash reference to the subroutine.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.