in reply to reuse worth it for small items?
I saw what some other people have done and to a certain degree they are missing the point of encapsulation and design.
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reuse worth it for small items?
by John M. Dlugosz (Monsignor) on May 08, 2006 at 15:25 UTC |