Ah, yes, "efficiency". The term's too broadly used here:
  1. There is the efficiency of your time as the coder. Will you reuse this code? Will it be faster for you to reuse it when it's in a module rather than finding another script that uses it and then cutting and pasting it? What if you need to upgrade the way the function does its work? Fix a bug/improve performance/increase functionality/etc. Will it be faster on your coding time to modify it in one place or go hunting for everyplace you've used it and fix them all?
  2. There is the efficiency of the time of others who use or maintain your code in the future. Same questions as #1, except without your preconceptions of how well you will be able to do these things, being familiar with how and where you did it the first time.
  3. There is the efficiency of the code at runtime. But do we mean efficiency of space (disk, memory, etc.) or do we mean efficiency of time (runtime)? And if we're talking about efficiency of execution speed, are we talking about a process that is run daily and takes 2 hours and we're looking to save 15 minutes, or are we looking at a process that will be run repeatedly throughout most days, takes 4 seconds to complete and we're looking to shave it down to 3? Honestly, how much savings are you expecting with the argument of "inline" vs. "module", and how much does that savings actually matter?
Context is everything, my friend. And in my experience, most things done in Perl aren't done with execution-efficiency overwhelmingly in mind. It is development efficiency that is of concern, as a rule, with a heavily intrusive emphasis on source-size efficiency (Using a regular expression that takes 5 minutes to create and adjust rather than 5 lines of index() and substr() code that take 30 seconds to write, for example).

I'm not saying it's a bad question to ask. I'm pointing out that, in my experience, in Perl, it's mostly academic and not particulary of practical concern.

Does it take longer to open a second file and read a few redundant lines out of that file than it would to open only one script file and read everything in one slurp? Probably. Does it actually have much of an impact on the interpretation/compilation phase? Probably not. Will it affect the execution speed? Maybe. Will it make enough of a difference to notice? Probably not.

My two cents.

Regarding the running theme of your question, however, I concur wholeheartedly -- knowing how to make and use a Perl module is a useful skill, and if you have an opportunity to learn it and pass on it, you are depriving yourself of a Perl tool for future use.

Just remember the 1;

     :-)


In reply to Re: Module Efficiency by marinersk
in thread Module Efficiency by Coplan

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.