Granted, it does not look quite right if you consider that the main point of a sub is to avoid code duplication (the DRY principle), but it is still better IMHO than having hundreds of cole lines in the main section of the program. Haqving a sub to isolate part of the program that have a well defined purpose if perfectly legitimate in my view, even if called only once (or twice).

I wholeheartedly agree. Although code reuse is an important motivation for subroutines, it's not the only one: it's equally important to be able to break up a program into smaller pieces that carry out a specific task. This makes it easier for the developer to understand the program: each individual subroutine will be easier to digest by virtue of its smaller size, and the main program will be written in a more abstract fashion, allowing the developer to focus on the bigger picture without constantly getting bogged down in details.

I sometimes think of the developer as the general commanding an army, and the tools the language provides as the individual foot soldiers. Subroutines are the ranks in between, officers and NCOs, allowing the general to say e.g. "fortify this position" without having to care about how exactly this is accomplished (by building trenches), or how trenches are built (by having the foot soldiers dig), or indeed about picking up a spade and moving soil from here to there.


In reply to Re^2: Indent, anonymous sub, or lexical sub for module private code? by AppleFritter
in thread Indent, anonymous sub, or lexical sub for module private code? by 1s44c

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.