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 is the use of -n and -p options?

765


what is the main function of fork() in cgi programming?

727


You want to add two arrays together. How would you do that?

632


Is perl compiler or interpreter?

700


List the files in current directory sorted by size ?

650






Explain split function in perl?

727


What is the purpose of “_file_ literal” and “_line_ literal” in perl?

694


Who created perl?

683


How to check the status of airplane mode (enable/disable) in perl for Android mobile?

2817


Which of these is a difference between Perl and C++ ?

734


What is q (single q) operator in perl?

699


What package you use to create a windows services?

648


How to remove a directory in perl?

655


What is it meants by '$_'?

675


What are the reasons that cookie server can’t handle multiple connections?

712