Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: use, require, do or what?

by massa (Hermit)
on Jul 30, 2008 at 20:18 UTC ( [id://701262]=note: print w/replies, xml ) Need Help??


in reply to Re^2: use, require, do or what?
in thread use, require, do or what?

Could you please explain to me exactly _how_ your employer's dev env precludes you from making proper modules and subroutines instead of loose .pl files? Modules can be put in the current dir, just like your .pl file in your example...
[]s, HTH, Massa (κς,πμ,πλ)

Replies are listed 'Best First'.
Re^4: use, require, do or what?
by AKSHUN (Novice) on Jul 31, 2008 at 14:13 UTC
    We only use modules that are a part of the core distribution of Perl.
      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 (κς,πμ,πλ)

        Given that OP & company use only the Perl core modules, them making their own module would disqualify it from usage causing unnecessary waste of resources. Now, pulling in another Perl program (aka "*.pl" ones) is all together different matter.

        ;-[

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://701262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found