Ah, yes, "efficiency". The term's too broadly used here:
- 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?
- 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.
- 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;
:-)