I think we are in different pages here.
I understand (at least sometimes) the need not to use anything outside perl core modules.
But my suggestion was for you to
make (not install! -- no root access needed) your own modules. It's basically the same thing as making another ".pl" file, but with many, many advantages (no namespace pollution, etc).
So, I'll repeat what I think you should do: instead of making a file called complex_calculation.pl, make a file called ComplexCalculation.pm, with the following contents:
use strict;
package ComplexCalculation;
sub do_calc {
# put your calculation here.
return 4 + 8 * 15 / 16 - 23 * 42;
}
1;
Now, in your scripts, everywhere where you had
require 'complex_calculation.pl' (*), you will put:
$variable1 = ComplexCalculation::do_calc();
And, at the top of those scripts, you will put:
use ComplexCalculation;
I am assuming that ComplexCalculation.pm and your scripts are in the same directory. Otherwise, before the
use line above, you have to put:
use lib '/some/path/to/the/calc/module';
(just the dir).
(*) Anyway, this would
NOT work unless the
require line was used only once each script, because
require does not read the same file again, when it alredy did.
In another note, always
use strict; use warnings; ...
Update:
You can still assign to multiple variables (even if you use only one calculation to figure them all) -- in ComplexCalculation.pm:
sub do_calc {
my $v1 = ##... something
my $v2 = ##... other thing
my $v3 = ##... a third thing
return $v1, $v2, $v3
}
and in your scripts:
my ($r1, $r2, $r3) = ComplexCalculation::do_calc()
Notice that each of your scripts may use its own relevant name for each variable, and they can even ignore one or more results:
my ($weight, undef, $depth) = ComplexCalculation::do_calc()
[]s, HTH, Massa (κς,πμ,πλ)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.