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.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to