×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Syntax

What's the difference between require and use? by MikeLacey
Posted: 28 May 02 (Edited 1 Feb 03)

Please browse through FAQ219-2884 and FAQ219-2889 first. Comments on this FAQ and the General FAQ's are very welcome.

Perl offers several different ways to include code from one file into another. Here are the differences between the various inclusion commands:

    1)  do $file is like eval `cat $file`, except that do
        1.1: searches @INC and updates %INC.
        1.2: gives an *unrelated* lexical scope to the eval'ed code.
    2)  require $file is like do $file, except that require
        2.1: checks for redundant loading, skipping already loaded files.
        2.2: raises an exception on failure to find, compile, or execute $file.
        2.3: It may help, if you're a C programmer, to think of require as being like #include
    3)  require Module is like require "Module.pm", except that require
        3.1: translates each "::" into your system's directory separator.
        3.2: primes the parser to disambiguate class Module as an indirect object.
    4)  use Module is like require Module, except that use
        4.1: loads the module at compile time, not run-time.
        4.2: imports symbols and semantics from that package to the current one.

Back to Perl FAQ Index
Back to Perl Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close