Hi Chas,

Can you give me an example when one would be used over the other? So, is
require used more for efficiency, so we load the module only if we need it?
Thanks,
-Ben

On Thu, Jan 22, 2009 at 2:50 PM, Chas. Owens <chas.ow...@gmail.com> wrote:

> On Thu, Jan 22, 2009 at 17:33, ben perl <ben.pe...@gmail.com> wrote:
> > Hi Everyone,
> > I am could never understand the difference between use vs require? If
> > "require" is older way of including modules, why not just make it
> obsolete.
> snip
>
> Well, first off, because use uses require.  The use looks something
> like this internally
>
> BEGIN {
>    require Module;
>    import Module args_to_use;
> }
>
>
> There is also a difference in when they run.  Because of the BEGIN
> block, use statements occur at compile time, so it is not possible to
> conditionally load a module (without eval).  The require function runs
> at runtime, so you can say things like
>
> if ($use_module_foo) {
>    require Module::Foo;
>    import Module::Foo;
> }
>
> --
> Chas. Owens
> wonkden.net
> The most important skill a programmer can have is the ability to read.
>

Reply via email to