This can be one of those divisive topics around the water cooler at work; and, as I'm seeing here, everyone has their own experience which leads to some similar answers and some different opinions on when to use subroutines. I'll throw my two-cents in as well.

For me, a subroutine is one of a number of solutions to help provide one of the following:

All of these things help to streamline your processing flow by reducing the amount of code someone (you or whoever might have to maintain it) has to read through to get a good understanding of what the code is doing.

Subroutines aren't the only way to provide this, and Perl, like many languages, offers a number of ways to provide modularization and code reuse. Subroutines can be separated into a separate file, a file of related subroutines could be made into a Module and even turned into an reusable Object.

All the commenters make good points, but I think you'll just have to take a look at your code while keeping these ideas in mind and see what makes sense.

---
echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'


In reply to Re: when to use subroutine by tuxz0r
in thread when to use subroutine by convenientstore

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.