in reply to subroutines and namespace
I think there is, though it would involve some XS programming. If you can find the CV (internal data structure holding a subroutine) you want to duplicate, you could theoretically copy it and change its stash value (lexical scope, basically) and stick it in the appropriate GV (symbol table). Any XS hackers out there care to enlighten us?
Barring that, is there a reason you can't use a closure?
You could also use placeholders and output binding, as in my DBI article. ;)sub make_booking_SQL { my ($BookingID, $ref_booking, $ref_event, $ref_course) = @_; return sub { $sth = $dbh->prepare("SELECT * FROM booking WHERE BookingID = +$BookingID") or die $dbh->errstr; $sth->execute(); $ref_booking = $sth->fetchrow_hashref; $sth = $dbh->prepare("SELECT * FROM event WHERE EventID = $ref_ +booking->{'EventID'}") or die $dbh->errstr; $sth->execute(); $ref_event = $sth->fetchrow_hashref; $sth = $dbh->prepare("SELECT * FROM course WHERE CourseID = $re +f_booking->{'CourseID'}") or die $dbh->errstr; $sth->execute(); $ref_course = $sth->fetchrow_hashref; }; }
|
|---|