On Thu, Jan 22, 2009 at 18:01, ben perl <ben.pe...@gmail.com> wrote:
> 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,
snip

Efficiency is one reason (loading modules you won't use is wasteful),
but the most common example would be something like a Factory
pattern*.  With a Factory, you don't know in advance what module you
will load.  Take, for example, the DBI*.  There are hundreds of DBD::
modules that could be loaded with more being written all the time.
You wouldn't want to install every one, let alone load every one every
time you used the DBI.  The proper DBD:: module gets loaded when you
call the connect method (which is a Factory).

* http://en.wikipedia.org/wiki/Factory_method_pattern
** http://search.cpan.org/dist/DBI/DBI.pm
-- 
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