require
require Math::Calc;
when the script is running
it reaches the above expression,
it will go over the directories listed in the @INC array,
check if any of them has a subdirectory called Math
and if that subdirectory there is a file called Calc.pm.
When it finds the fist such file, it loads it into memory, compiles it and stops the search.
This will let you use the functions of the module with their fully qualified name (eg. Math::Calc::add())
use
use Math::Calc;
use Math::Calc qw(add);then perl will load and compile the module
during the compilation time of the script.
That's because having use in the script will be replaced
by the following piece of code in the file:
BEGIN {
require Math::Calc;
Math::Calc->import( qw(add));}
What the import method does is up to the author of the (Math::Calc) module,
but inmost cases it will arrange for
the addfunction to be inserted in the name-space of the code
where the use statement was located
so that the author of that code can call add
without providing the fully qualified name
Math::Calc::add() of the function.
require happens at run-time,
and use happens and compile-time
and the use, in addition to loading the module,
it also imports some functions into the current name-space.