laziness, impatience, and hubris | |
PerlMonks |
Re: Require in modules...?by Joost (Canon) |
on May 10, 2009 at 02:06 UTC ( [id://763098]=note: print w/replies, xml ) | Need Help?? |
require only loads a file if it hasn't been loaded yet, given reasonable checks, so it (normally) won't include stuff twice. and even if it *did* load the module twice, that probably doesn't mean you get multiple copies - that's all dependent on the scoping rules - "global" entities like named functions are unique and you cannot have more than one of them at the same time. Also, I consider it good form for a module to use/require all the code it depends on instead of relying on the user to do that.
Anyway, that's to say that you can usually use require wherever you want. Now, it's probably better to use use instead, since use directives are processed earlier, and all you have to do to convert "data_defs.pl" to a useable module is to to rename it to "data_defs.pm" (that name is contrary to conventions but it'll work all the same). None of this has anything to do with OO - it's just a code loading mechanism - and also, you probably should not use Switch, since it can really mess up your code.
In Section
Seekers of Perl Wisdom
|
|