Re: "use" vs "require"
by Corion (Patriarch) on Aug 07, 2006 at 13:05 UTC
|
| [reply] |
Re: "use" vs "require"
by Velaki (Chaplain) on Aug 07, 2006 at 13:11 UTC
|
According to the manual, use is the equivalent of
BEGIN { require Module; import Module LIST; }
except that Module must be a bareword.
It really comes down to if you wish to import names into your current namespace, so that you would be able to type bar(), and not Foo::bar(). Your project will dictate which is better at the time.
Hope this helped, -v.
Update: Kudos to friedo for reminding me in his post that there is also the matter of whether you want your code loaded at compile-time vs. runtime.
"Perl. There is no substitute."
| [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
|
| [reply] |
|
I find that fully qualified calls to imported subs makes it easier to decipher the code at some later date. Otherwise the reader has to look up the sub in their head, or perldoc, when it could be right there where they need it most.
| [reply] |
|
use Module;
use
use Module qw( func1 func2 );
| [reply] [d/l] [select] |
Re: "use" vs "require"
by bobf (Monsignor) on Aug 07, 2006 at 15:22 UTC
|
| [reply] |
Re: "use" vs "require"
by gellyfish (Monsignor) on Aug 07, 2006 at 13:06 UTC
|
| [reply] |
Re: "use" vs "require"
by izut (Chaplain) on Aug 07, 2006 at 13:10 UTC
|
| [reply] |
Re: "use" vs "require" vs "do"
by ikegami (Patriarch) on Aug 07, 2006 at 16:56 UTC
|
and others with require (require "Simple.pl").
Files with no package should be included using do, not require or use.
| [reply] [d/l] |
|
| [reply] |
|
Exactly. require will mysteriously fail if two modules need to use the file. It's a good habit to use do instead. You never know what someone will do in the future.
There's another reason. Using do over require conveys more information to the reader. Since modules must not be loaded using do, it's safe to assume something loaded using do is not a module. Using require wouldn't be as clear.
| [reply] [d/l] [select] |
|
Re: "use" vs "require"
by kulls (Hermit) on Aug 08, 2006 at 03:09 UTC
|
As simple
Try this in the command prompt.
$shell> perl
use Module; # Not installed in your machine
$shell> perl
require Module; # Not installed in your machine
you must feel the difference I guess.
Thanks,
kulls
| [reply] [d/l] |