Dear Stew,
It really sounds like you have been hitting your head against some really basic and well-known mod_perl things. So the last post about RTFM is an extremely good idea. Mod_perl requires a bit of reading when you start and then some experimentation until you get used to it.
Regarding your questions:
- mod_perl embeds a single persistent perl interpreter instance in apache as opposed to launching a new one each time a page is opened. So you typically use a parent program (launched once when the server is soft-restarted) and a child program (called from a browser, but also sharing the memory of the parent).
- This means if you use global variables they will clobber you right on the head, being shared across all calls to one or all of the apache server child processes. one of the very first programming examples (a counter) in the docs does what you are talking about. (hint: use lexicals)
- Likewise with database connections, if you happen to open a db connection in your child code it will stay open. probably would work if you undef'd it but you can also open a connection in the parent, there is in fact a connection pool module for this purpose. read about it.
- In general the really extremely good advice is to use strict. mod_perl *will* have your brain for breakfast if you do not use strict. 'nuf said.
- If you are porting from CGI there is also good documentation in the same place on porting from cgi.
Good luck. Mod_perl is definitely worth it, but you have not yet invested the time and effort required to get you into it, since you would already be using strict if you had even opened the cover of the book. Just the first part of the free documentation might be enough but then you will want to read more, hopefully. I recommend if you don't like reading, to stop using mod_perl since you get out of it exactly what you put into it. Of course you can run like CGI in this environment, see the docs.