in reply to Packages and modules

I'm not sure what more I can really tell you about what I'm doing -- I just want to communicate some data (in this case just a scalar value, a string) to a module from the code using the module.

That's kind of what I've been thinking -- that writing my own import routine would be overkill, but I wasn't sure if that is the traditional way to do what I'm trying to do.

Thanks for the suggestion, I guess that approach will suffice.

I'm a little surprised that people haven't been quicker to explain how they actually do this in their modules -- this must be a pretty common need, to pass an argument to a module, isn't it?

JMM

Replies are listed 'Best First'.
Re: Re: Packages and modules
by jsegal (Friar) on Jan 09, 2003 at 22:06 UTC
    In general, I have two types of modules:
    • Modules which are really related collections of functions
    • Modules which implement classes for OO perl
    In the former case, the Modules themselves are "stateless" -- i.e. they have no variables of its own. All data is passed to the various functions as function arguments. If those functions call other functions, they pass what arguments they need.

    In the latter case, data is passed in to the modules as parameters to the objects (as someone else already mentioned), and thus the data can be shared among the functions without being explicitly passed.

    Module-level state is problematic -- if multiple subsystems of your code use the same module, they might bang into each other.

    This is the same problem in general with global variables -- they act against subsystem decoupling, which is a powerful technique for minimizing the complexity, and thus increasing the reliability and extensibility, of the systems we are building.

    This is not to say that module-level state should never be used, but you should think carefully about the extensibility ramifications if you do use it, and have a good reason to pay this cost.

    Sort of a long answer for saying "function paraments or object instance variables..." I hope this helps...

    --JAS