in reply to "use" vs "require"

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."

Replies are listed 'Best First'.
Re^2: "use" vs "require"
by friedo (Prior) on Aug 07, 2006 at 13:14 UTC
    It really comes down to if you wish to import names into your current namespace

    Well, no. It also comes down to whether you want code loaded at compile-time or runtime. And you can always manually call import if you require a module.

      Thanks! Yeah, forgot about that one.

      -v.
      "Perl. There is no substitute."
Re^2: "use" vs "require"
by Anonymous Monk on Aug 07, 2006 at 19:43 UTC
    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.

      An alternative is to explicitely state all the imported functions in the use statement. For example, instead of saying

      use Module;
      use
      use Module qw( func1 func2 );