Is there a better way to generate all these funcions?
Use closures. This should get you started:
sub make_closure {
my ($table, $column) = @_;
return sub {
my $id = shift;
my $dbh = sqlConnect();
my $sth = $dbh->prepare("SELECT * FROM $table WHERE $column=?"
+);
$sth->execute($id);
my $result = $sth->fetchrow_hashref();
$sth->finish();
return $result;
};
}
local *getCustomerById = make_closure("customers", "cust_id");
local *getUserByUserId = make_closure("users", "user_id");
-sauoq
"My two cents aren't worth a dime.";