Explain the difference between use and require?

Answers were Sorted based on User's Feedback



Explain the difference between use and require?..

Answer / kush

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.

Is This Answer Correct ?    38 Yes 6 No

Explain the difference between use and require?..

Answer / gopi sreekanth

use can take a bareword and require doesnot while accessing
module
use is used in compile time ie all code is parsed before
program run where as require is used in run time. So if
there is much code in initialization include that in use
rather than require
use supports import method by default and require doesnt
support
Inside use default import method will be present. BEGIN {
require Module; }

Is This Answer Correct ?    2 Yes 1 No

Explain the difference between use and require?..

Answer / goyal

Please refer:
http://www.techopes.com/2014/09/difference-between-use-and-require-in.html

Is This Answer Correct ?    2 Yes 1 No

Explain the difference between use and require?..

Answer / vipul dalwala

- a require statement imports the functions and objects
only within their defined packages. The use keyword, on the
other hand, imports the functions and objects so they are
available to the current package as if they had been
defined globally. For example,

require Cwd;
$pwd = Cwd::getcwd();

as opposed to

use Cwd;
$pwd = getcwd();

- use statements are interpreted and executed at the time
the file is parsed, but require statements import modules
at run time, which means you can supply a variable name to
a require statement based on other elements of your program.

Is This Answer Correct ?    9 Yes 9 No

Explain the difference between use and require?..

Answer / vinoth.g

The use statement works at compile time, require at run
time. So if you have a module that does a lot in a begin
block and you don't really need it in all cases, then it's
clever to "require" it there where you want to use it but
don't "use" it. So you don't have to wait for all that
initializations of that module in case you don't need it.

Is This Answer Correct ?    5 Yes 5 No

Post New Answer

More CGI Perl Interview Questions

What is a perl references?

0 Answers  


Can you add two arrays together?

0 Answers  


You want to concatenate strings with perl. How would you do that?

0 Answers  


What is perl push array function?

0 Answers  


In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?

0 Answers  


Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?

0 Answers  


sort a word "system" in perl/shell without using built in functions output should be emssty

2 Answers   emc2,


What is the difference between chop & chomp functions in perl?

10 Answers   Cap Gemini, DELL, Electronic Data, TCS,


Explain USE and REQUIREMENT statements?

0 Answers  


What do the symbols $ @ and % mean when prefixing a variable?

1 Answers   Barclays,


Define operators used in perl?

0 Answers  


Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

0 Answers  


Categories