After lurking around the monastery for several months, and realizing I've written a lot of sloppy code, I've decided to rewrite a small web-based content manager a la PM style (warnings, strict, traint, etc.) and to make it more efficient (smaller). The script currently works fine, but is about 1000 lines (I know this is short for some of you system admin folks), and besides using the aforementioned good coding practices, I'd like to trim down the code by about 2/3rds.
(and I think this is a rather fundamental one): do I write a large program with a bunch of subroutines, or have a smaller program with a bunch of modules (like as in 'use foo.pm')? In the current program, the scripts are all related to the content mgr., but are performing a variety of tasks—mostly basic MySQL stuff like INSERT, UPDATE, SELECT, and then prepping variables for HTML::Template.
I've done some searching of PM and Google and have found a few things, among others, a rather passionate node
on where to put your subs, or a piece
on writing long programs (more on how to organize functions within the program). Found some caveats on variable scoping causing problems in longer scripts.
I'm sure there are many others, they just aren't coming to the fore.
So, any advice, previous nodes, articles, books, CPAN modules to shed some light on this topic, or is it beyond the scope of SoPW?
Thanks fellow monks!