in reply to Call subroutine by reference ?
Taking a slightly less literal viewpoint to your situation ... what I would do is to spin-off the common subroutines into a Perl package that you can then use in any of the scripts that need to refer to them. Now, any number of scripts can incorporate the code (i.e. “can reference” in the colloquial sense of “can refer to”) without textually including it.
The different variations of the 4th-stage analysis subroutine can likewise be implemented as additional packages. Now, each one of them also becomes something that can be “referred to” without textually including it.
A very short script can now be written, which uses (or on-demand requires), each of these other units, and which contains the logic to invoke their contents in an appropriate sequence. For example, consider this purely-illustrative (don’t try to run this at home!) sketch:
use stages_1_thru_3; # common preamble use stage4_huey; # analysis routines use stage4_dewey; use stage4_louie; ... stages_1_thru_3::run_preamble(); # run the common code # now pick a 4th-stage subroutine to run if ( $method eq 'huey') { stage4_huey::huey_analysis(); } elif {$method eq 'dewey') { stage4_dewey::quack(); } ... blah ... else { die "Sorry, I don't know about '$method'"; } ...
I’ve bent the rules of Perl syntax quite freely for the purposes of illustration. Any script or package which uses another package immediately gains access to whatever’s in it, in its current version as of the instant that the useing script is run. Thus, there is no duplication of source-code and no problem with versioning. “The code that users execute in order to do things” (scripts ...) are now at an arm’s length removed from “the units of code that are common to all of them (packages ... modules...), which are “incorporated by reference” anywhere that they are needed.
Does my interpretation have anything to do with the other responses previously given? N-o. Keep that in mind. I have assigned a different human meaning altogether to your use of the word, “reference.” Other responses in this thread have employed a more technical (and Perl-specific) meaning of the same word. Which one is correct is up to you, but they are apples and oranges. Don’t read them together.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Call subroutine by reference ?
by JockoHelios (Scribe) on May 31, 2013 at 17:28 UTC |