I use packages and break out into subs for two major reasons: maintainability and reuse.

That way, I can break out items that I use often, as you have done with PassMaster, and have a single place to fix bugs. Imagine if you had used PassMaster instead as simply a cut and paste snippet, and put it in some 12 scripts. Then, later along, you realize that the masking becomes ineffective if the user sends a certain excape sequence! Sure, fixing 12 scripts can be done, but we're lazy, aren't we? Yes.

I also tend to start my projects by starting a bit on each major component, and put things into packages as I go. That way, if I realize that I've already written something, all I have to do is use it. Boy am I making things easy for myself ;)

When done right, using subs and packages also makes it easy to expand your code, or refactor it (to an extent). If you haven't noticed the real point yet, it's all about making things easier on you. It's just a little effort for a big payoff.

P.S.: I don't believe you need the brackets in the DataBase Interface section -- the package statement applies until the next package or end of file. diagnostics should probably left out when the code goes to production, too. :)

Update: Oh also, ++ for the question! I expect some great responses coming soon!

mhoward - at - hattmoward.org

In reply to Re: When Is Dividing Code Into Different Subroutines/Packages Important? by meredith
in thread When Is Dividing Code Into Different Subroutines/Packages Important? by Missing Words

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.