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 = $ref_booking->{'CourseID'}") or die $dbh->errstr; $sth->execute(); $ref_course = $sth->fetchrow_hashref; }; }