sub build_selector { my ($dbh, $table, $field, @selectables) = @_; my $selectables = join ',', @selectables; return sub { my ($val) = @_; die "No val passed into selector" . $/ unless defined $val && length $val; my $sth = $dbh->prepare_cached(<<"_SQL_"); SELECT $selectables FROM $table WHERE $field = ? _SQL_ die "Couldn't prepare handle: " . $dbh->errstr unless $sth; $sth->execute($val) || die "Couldn't execute handle" . $dbh->errstr; my @vals = $sth->fetchrow_array; $sth->finish; return wantarray ? @vals : \@vals; }; }