Have you consider the Model/View/Controller (MVC) method for organizing your code? The O'Reilly book "Managing and Using MySQL" has a good description of MVC.
Plankton: 1% Evil, 99% Hot Gas.
Comment on Re: Lots of subs in large program vs lots of small programs