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

Explain grooving and shortening of arrays and splicing of arrays?

501


Explain the difference between declarations of 'my' and 'local' variable scope in perl?

502


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

589


Why to use perl scripting?

523


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

531






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

566


What is subroutine in perl?

528


How will you create a file in perl?

521


List the prefix dereferencer in Perl.

566


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

546


Explain perl. What are the advantages of programming in perl?

564


What are the logical operators used for small scale operations? Explain them briefly.

543


Why should I use the -w argument with my Perl programs?

556


Explain substr function in perl?

538


Explain goto label?

511