Explain the difference between use and require?

Answers were Sorted based on User's Feedback



Explain the difference between use and require?..

Answer / kush

Use :

1. The method is used only for the modules(only to include
.pm type file)

2. The included objects are varified at the time of compilation.

3. No Need to give file extension.

Require:

1. The method is used for both libraries and modules.

2. The included objects are varified at the run time.

3. Need to give file Extension.

Is This Answer Correct ?    38 Yes 6 No

Explain the difference between use and require?..

Answer / gopi sreekanth

use can take a bareword and require doesnot while accessing
module
use is used in compile time ie all code is parsed before
program run where as require is used in run time. So if
there is much code in initialization include that in use
rather than require
use supports import method by default and require doesnt
support
Inside use default import method will be present. BEGIN {
require Module; }

Is This Answer Correct ?    2 Yes 1 No

Explain the difference between use and require?..

Answer / goyal

Please refer:
http://www.techopes.com/2014/09/difference-between-use-and-require-in.html

Is This Answer Correct ?    2 Yes 1 No

Explain the difference between use and require?..

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

Explain the difference between use and require?..

Answer / vinoth.g

The use statement works at compile time, require at run
time. So if you have a module that does a lot in a begin
block and you don't really need it in all cases, then it's
clever to "require" it there where you want to use it but
don't "use" it. So you don't have to wait for all that
initializations of that module in case you don't need it.

Is This Answer Correct ?    5 Yes 5 No

Post New Answer

More CGI Perl Interview Questions

What is use of ‘->’ symbol?

0 Answers  


Explain string comparison operators in perl.

0 Answers  


my @array=('data1','data2'); my @array1=('data1','data2'); my ($i,$k); $i=7; $k=7; while($i){ $array [++$#array] = 'ree'; $i--; print "@array"; } while($k){ push(@array1,'ree'); $k--; print "@array1"; } Are these two while loop are doing the same functionality ? What may be the difference?

1 Answers   A1 Technology,


What is perl push array function?

0 Answers  


while (my ($key, $value) = each(%ENV)) { print "$key - $value\n"; } What does the above sample code produce? What function do you use for reading a list of files within a directory? my %hash = ( 'hi' => {'hello' => 'all'}, 'bye' => {'later' => 'gone'} ); print $hash{'hi'}; What is printed when the above code is executed? sub new { my $pkg = shift; my $test = {'name' => shift;}; ???? return $test; } Which one of the following replaces "????" in the above code in order to cause the function new to return an object of type "Test"? while (<STDIN>) { ???? print "$_\n"; } Which one of the following statements causes the above code to strip all whitespace from the end of all lines of input and to print the resulting lines to standard output while (my ($key,$value) = each(%hash)) { print "$key - $value\n"; delete $hash{$key}; } open(FILE,"<file.dat"); my $data = ''; { local $/ = undef; $data = <FILE>; } close(FILE); my $foo = 21; $foo <<= 5; $foo >>= 4; print $foo; @arr = (1,2,3); {local $" = "\n"; print "@arr\n"; } my $line = "Hello World"; substr($line,5,2) = "abc"; print $line; Why is sprintf rarely used in perl in comparison to similar (or the same) functions in other languages? my $subRef = sub {print shift;}; How is the subroutine above called with one parameter? How can the values of an associative array be placed in sorted order in a new array? What function is often necessary for building data structures to be passed to low-level routines such as ioctl and fcntl? sub foo { if (shift(@_) > 0) { shift; } } print foo(10,5); print foo(-10,5); What does the above sample for (my $i = 1; $i <= 3; $i++) { print 1..$i; print "\n"; } my $data = 5**3 * 12,2+2; print $data; sub foo { my $value = shift; if ($value) { print 1; shift; } else { return shift(@_) + 3; } } print foo(10,20); What is printed as the result of executing the above code? $var = 20; sub s1 { print "$var "; } sub s2 { local $var = 10; s1;} sub s3 { my $var = 30; s1;} s3; s2; s1; On systems that record file ownership, how may the owner of a file be identified? Which one of the following sets $y to be a copy of $x with every occurrence of foo changed to bar? Which one of the following is an array literal that represents a 4-element array containing the numbers 1, 4, 2, and 6? sub foo {2*shift || 'x';} printf ("%s %s %s", foo(5),foo(0),foo(-5)); What does the above sample code print? Suppose $x contains a number. Which one of the following statements sets $y to be a string containing the octal value of $x?

2 Answers  






How to convert arrays into a string in perl?

0 Answers  


Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

0 Answers  


What do the symbols $ @ and % mean when prefixing a variable?

1 Answers   Barclays,


Who created perl?

0 Answers  


what r the different type of function in perl ???

1 Answers   ABC, Symphony,


Can any1 tell me 2 write the script using perl script 2 looking at a log file 2 see wheather the test has passed or not.

3 Answers   TCS,


How to implement a stack in Perl?

0 Answers  


Categories