What is difference between "Use" and "require". In which case should "Use" be used and not "Require"?

Showing Answers 1 - 10 of 10 Answers

Pallavii Potdaar

  • Feb 15th, 2006
 

Use :

1. The method is used only for the modules(only to include .pm type file)

2. The included objects are varified at the time of compilation.

3. No Need to give file extension.

Require:

1. The method is used for both libraries and modules.

2. The included objects are varified at the run time.

3. Need to give file Extension.

"use" is a keyword to incorporate a module (.pm file) at compile time whereas "require" can be used to import a package or a module at run time.

While using "use" keyword, we dont need to specify the file extension.only the file name is required.

suppose we have a module file as myModule.pm

use myModule;

or

require "myModule.pm";

will do the same job.

1)Use

i) use for loading the modules( Should not give the .pm extension)
ii) The loaded module is verified at the compile time.

2) Require

i) Use for loading the modules and perl programs( .pm extension is not necessary; but perl program require .pl extension)

ii) The loaded module is verified at the run time.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions