in reply to dbh->disconnect or leave to scope

mod_perl,” o’course, “is a very different kettle o’ fish,” because of its inherently persistent nature as an integrated part of the long life of the web-server process(es).

As mentioned in http://modperlbook.org/html/20-1-1-Apache-DBI-Connections.html (for example...) database handles routinely get special treatment in the mod_perl environment, and these treatments are more-or-less designed to ignore exactly what you do.

Nevertheless, in writing my original code, for whatever environment, I do try to follow this gentlemanly maxim:   “Be tidy.   Wipe the toilet seat.   Flush.   Lower the lid for the next lady.”   Whatever you open, close.   Don’t throw your trash on the ground and expect some faceless public worker to clean up after you.   More-reliable code will be your reward.

Replies are listed 'Best First'.
Re^2: dbh->disconnect or leave to scope
by tilly (Archbishop) on Jan 17, 2011 at 23:11 UTC
    Following your maxim you'll wind up with a bunch more code, but I'm not sure what actual benefit you're hoping to wind up with in Perl. If you just use autodie and properly scoped variables you'll get the same effect with fewer bugs. (Assuming that you its error handling behavior is sufficient for you.)

    Of course this doesn't hold if you're using a different language. For instance in C++ stuff doesn't get closed at all and you'll leak memory. Alternately in a true garbage collected language like Java it won't get closed until the next gc run, and you can wind up running out of resources because of leaked handles, which is also bad.

    But if you're coding in Perl, you might as well take advantage of the features it offers. And prompt cleanup of stuff is one of them.