in reply to "Use" vs "Require"

A rule of thumb: use 'use' unless you have a good reason to use 'require'. If you're unsure what to use, use 'use'.

For a short answer, what 'use' does is, it compiles the module (if not compiled already), then runs its code (this is not different from what require does). Afterwards, it calls the import routine (require doesn't do so). And all of it is done at compile time (require does it at runtime).

For a longer answer, and a more detailed explaination of all the differences (I've left out some details) consult the manual pages.

Replies are listed 'Best First'.
Re^2: "Use" vs "Require"
by leocharre (Priest) on Jan 21, 2009 at 21:01 UTC

    Getting a module via require, you can import. But you have to do so explicitly.

    Bad:

    require Cwd; print cwd();

    Good:

    require Cwd; Cwd->import; print cwd();

    Also fine, does not import:

    require Cwd; print Cwd::cwd();