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) [tt]do $file[/tt] is like [tt]eval `cat $file`[/tt], except that [tt]do[/tt]
1.1: searches [tt]@INC[/tt] and updates [tt]%INC[/tt].
1.2: gives an *unrelated* lexical scope to the eval'ed code.
2) [tt]require $file[/tt] is like [tt]do $file[/tt], except that [tt]require[/tt]
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 [tt]require[/tt] as being like #include
3) [tt]require Module[/tt] is like [tt]require "Module.pm"[/tt], except that [tt]require[/tt]
3.1: translates each "::" into your system's directory separator.
3.2: primes the parser to disambiguate class Module as an indirect object.
4) [tt]use Module[/tt] is like [tt]require Module[/tt], except that [tt]use[/tt]
4.1: loads the module at compile time, not run-time.
4.2: imports symbols and semantics from that package to the current one.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.