in reply to Re^4: use, require, do or what?
in thread use, require, do or what?
Now, in your scripts, everywhere where you had require 'complex_calculation.pl' (*), you will put:use strict; package ComplexCalculation; sub do_calc { # put your calculation here. return 4 + 8 * 15 / 16 - 23 * 42; } 1;
And, at the top of those scripts, you will put:$variable1 = ComplexCalculation::do_calc();
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 ComplexCalculation;
(just the dir).use lib '/some/path/to/the/calc/module';
and in your scripts:sub do_calc { my $v1 = ##... something my $v2 = ##... other thing my $v3 = ##... a third thing return $v1, $v2, $v3 }
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 ($r1, $r2, $r3) = ComplexCalculation::do_calc()
my ($weight, undef, $depth) = ComplexCalculation::do_calc()
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: use, require, do or what?
by parv (Parson) on Aug 01, 2008 at 02:35 UTC | |
by massa (Hermit) on Aug 01, 2008 at 15:01 UTC | |
by AKSHUN (Novice) on Aug 19, 2008 at 19:50 UTC |