Dear Monks,

I am finally to the point where I have half decent code that I reuse increasingly. In the spirit of avoiding duplication and improving maintainability I found myself putting that in a standalone script. In a nutshell, it is saving specific email attachments to a given path, since I need to get the filenames for further processing, a call from a "master" Perl script via backticks seemed in order.

My naive thought is the following: an external script seems less convenient to retrieve results than returning them back from a subroutine via a reference. However if I start pasting my code as a subroutine in a few different scripts, any improvement I make will have to be updated in all of them.

I suspect making my own module/package may be a way to address this but my code is probably not yet generalized enough and frankly, the thought of making my own module is intimidating for a perpetual newbie like me.

Question:Is the road I am taking (i.e. using external calls) a sustainable approach in the midterm or I am missing something completely obvious?

As always your guidance will be appreciated.

Update: Thanks to all for your encouragement and relevant links. I guess I must be feeling like my son did when I removed the training wheels from his bike... It's probably time for me to get going and build a first module

Update 2: Thanks again to all the posters below, this is the very very best advice I ever had (and followed!). I worship you!!


In reply to Naive monk trying to make distinctions among subs, external calls and code reuse by jjap

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.