Explain the difference between use and require?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different ways to run cgi?

716


What are prefix dereferencer?

703


What is -> symbol in perl?

769


What does redo statement do in perl?

811


What is the difference between use and require in perl?

676


What is the main function of cookie server?

760


How do I send e-mail from a Perl/CGI program on a Unix system?

787


What value is returned by a lone `return;’ statement?

810


Which functions in perl allows you to include a module file.

696


What are stdin, stdout and stderr?

719


How to create a package?

733


Explain use of ‘my’ keyword in perl?

750


What are the advantages of programming in perl?

751


How do I replace every character in a file with a comma?

740


What are the various uses of perl?

745