in reply to Creating A Dynamic Subroutine

Answering your direct question, pass a reference. To deal with the database issue, perhaps an idea from this article may help?