in reply to subroutines and namespace

So, my thought. I think it might be nice if there was a way to make a subroutine behave, in regard to naming scopes, exactly the same as if, instead of calling the module, you had cut and pasted the lines of code into your script in place of the subroutine call.

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?

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; }; }
You could also use placeholders and output binding, as in my DBI article. ;)