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.

My question(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 by tilly 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!


In reply to Lots of subs in large program vs lots of small programs by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.