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
Explain grooving and shortening of arrays and splicing of arrays?
Explain the difference between declarations of 'my' and 'local' variable scope in perl?
How do I send e-mail from a Perl/CGI program on a Unix system?
Why to use perl scripting?
How do I replace every character in a file with a comma?
Which of these is a difference between Perl and C++ ?
What is subroutine in perl?
How will you create a file in perl?
List the prefix dereferencer in Perl.
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
Explain perl. What are the advantages of programming in perl?
What are the logical operators used for small scale operations? Explain them briefly.
Why should I use the -w argument with my Perl programs?
Explain substr function in perl?
Explain goto label?