> -----Original Message-----
> From: Elaine -HFB- Ashton [mailto:[EMAIL PROTECTED]]
> Sent: Friday, November 16, 2001 10:28 AM
> To: [EMAIL PROTECTED]
> Cc: Ray Murphy; [EMAIL PROTECTED]
> Subject: Re: Modules
>
>
> Jeff 'japhy' Pinyan [[EMAIL PROTECTED]] quoth:
> *>On Nov 16, Ray Murphy said:
> *>
> *>>When using modules, is it better to say 'use
> *>>Foo::Bar;' rather than 'require'. Also I've noticed
> *>>that some people put their 'use' or 'require'
> *>>statements in subroutines and not at the beginning of
> *>>the program - what benefits does this serve - conserve
> *>>memory because as soon as you've left the routine the
> *>>module goes bye bye (guessing)?? But surely the
> *>>library would have to compile everytime the subroutine
> *>>would be called and therefore slow the program down
> *>>somewhat (again, guessing).
> *>
> *>The FAQ has an answer for this: "What's the difference
> between require and
> *>use?" Check http://www.perldoc.com/, and look in perlfaq8.
> *>
> *>The skinny is this:
> *>
> *> 1. require() happens at run-time, and either takes a
> bareword module
> *> name or a path to a file (not necessarily a module)
> *> 2. use() happens at compile-time (so putting it in a
> function doesn't
> *> "help") and it involves require()ing a module and then
> calling its
> *> import() method
>
> In practical daily use, use(); is preferred as since it compiles the
> module as soon as it sees 'use Foo::Bar;' before moving on, this will
> catch errors and scope conflicts far sooner than if you use require();
> There aren't many good reasons to use require, at least I
> can't think of
> any. When in doubt, use use(); :)
>
> If you see a lot of 'requires' in subroutines, I suspect someone just
> didn't get scope or wrote a quick hack so performance is the
> least of the
> codes worries.
require() is handy inside an eval { } block to trap whether a module
is installed or not. Many CPAN modules use this technique.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]