[Israel.pm] use and require

Ronen Angluster beerholder at gmail.com
Sun Mar 20 23:32:15 PDT 2011

to make things simple (and i'll admit that i did not bother to read the
entire thread...):
"use" is a combination of 2 actions: "require" & "import" and is executed
while require when called is executed during run time.
what it means is that if you "use" a module, it will be loaded and imported
during the compile phase of the interpreter
while "require" is used to load classes dynamically.
just to further clarify things, compile time is a phase where variables are
not populated and only rudimentary (this will probably cause me to be flamed
into hell) calculations are carried, for example: all "use" directives are
executed, all constants are populated and so on.

myself, i prefer using "Module::Load" as it provides a more clean interface
and also imports the required class.

hope this clear things a bit


On Mon, Mar 21, 2011 at 8:17 AM, Levenglick Dov-RM07994 <
RM07994 at freescale.com> wrote:

> Taking this 17 steps back, although there is extensive documentation I have
> yet to fully grasp the difference between use and require. I know it well
> enough to explain to people who know less about perl than I do - but I don't
> truly understand.
> Would someone, without quoting perldoc or sending me to RTFM, please
> explain the mechanics of the difference; all ramifications included.
> Best Regards,
> Dov Levenglick
> SmartDSP OS Development Leader
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
> Of Shmuel Fomberg
> Sent: Sunday, March 20, 2011 05:15
> To: Perl in Israel
> Subject: Re: [Israel.pm] use and require
> On 2011/03/13 19:45, sawyer x wrote:
> >
> >     Whenever I see 'require' used instead of 'use', I expect problems
> >     in the
> >     module-dependency tree.
> >
> >
> > I think there are benefits to both. It depends, as always, on your needs.
> >
> > If you have a healthy build process, you can use "require" instead of
> > "use" when you want to allow some features to be lazy, and that's very
> > useful. You can also allow loading two different versions of the same
> > mechanism, depending on some logic. If you have this, load that one,
> > if not, load this one. Imagine Mouse only uses Moose if it's already
> > loaded, saving you a ton on compile-time.
> While you are right, I think that these 'require' statements should be
> in very specific places. plugins finding and loading code, dynamic
> feature loading, and so on.
> but not littered through the code.
> Especially the main perl file, should 'use' all the modules that are
> known to be needed for running it. no point leaving it to later point of
> time.
> Shmuel.
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://mail.perl.org.il/mailman/listinfo/perl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20110321/10aa4ab8/attachment.htm 

More information about the Perl mailing list