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

Which operator in perl is used for the concatenation of two strings?

508


What syntax is used for grep() function?

579


Write a program to download the contents from www.perlinterview.com/answers.php website in Perl.

544


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

537


what is Polymorphism in Perl?

551






What are the advantages of programming in perl?

543


How to determine strings length in perl?

543


How to copy a file in perl?

526


How do you turn on the perl warnings?

506


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

493


How many types of variable in perl?

561


What is a chop() function in perl?

582


what is Chop & Chomp function does?

603


How to access parameters passed to a subroutine in perl?

547


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

558