“use”
The method is used only for the modules (only to include .pm type file)
The included objects are verified at the time of compilation.
We don’t need to specify the file extension.
loads the module at compile time.
“require”
The method is used for both libraries and modules.
The included objects are verified at the run time.
We need to specify the file Extension.
Loads at run-time.
suppose we have a module file as “Module.pm”
use Module;
or
require “Module.pm”;
(will do the same)
13) How can you define “my” variables scope in Perl and how it is different from “local” variable scope?
$test = 2.3456;
{
my $test = 3;
print "In block, $test = $test ";
print "In block, $:: test = $:: test ";
}
print "Outside the block, $test = $test ";
print "Outside the block, $:: test = $::test ";
Output:
In block, $test = 3
In block, $::test = 2.3456
Outside the block, $test = 2.3456
Outside the block, $::test = 2.3456
The scope of “my” variable visibility is in the block only but if we declare one variable local then we can access that from the outside of the block also. ‘my’ creates a new variable, ‘local’ temporarily amends the value of a variable.