in reply to Code factory
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.";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Code factory
by hmerrill (Friar) on Jul 07, 2003 at 20:07 UTC | |
by sauoq (Abbot) on Jul 07, 2003 at 20:24 UTC | |
by dragonchild (Archbishop) on Jul 07, 2003 at 20:13 UTC | |
by sauoq (Abbot) on Jul 08, 2003 at 17:31 UTC | |
Re: Re: Code factory
by Notromda (Pilgrim) on Jul 07, 2003 at 20:03 UTC | |
by sauoq (Abbot) on Jul 07, 2003 at 20:12 UTC | |
by Notromda (Pilgrim) on Jul 08, 2003 at 16:35 UTC |