Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

USE vs REQUIRE 3

Status
Not open for further replies.

garymgordon

Programmer
Apr 5, 2000
307
US
With regard to finding modules?


Why does:

require 'c:\temp\Employee.pm';


work ok, yet ...

use 'c:\temp\Employee.pm';


doesn't?

Can you explain .. and tell me how I could do this with USE and have it find the location of this file, in a particular directory?

Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
The main difference between use and require is that use works on compile time while require works in run time.

require works just like #include in C. A piece of code is loaded into your program replacing the require/#include statement.

use however attempts to load a package at compile time. So the argument is not a filename but a packagename.

in your example you should change

use 'c:\temp\Employee.pm';

into

use Employee;

Be sure to name your file Employee.pm and be sure that the file can be found in your include-path.

Good Luck

Søren
 
Thanks.

RE: Be sure to name your file Employee.pm and be sure that the file can be found in your include-path.


How do I set up the file so it can be found in the include-path?

PS: What is the include-path?

(Stop laughing at me. I am new to Perl and just trying to figure things out. But I thank you for your help.)

Gary
Gary M. Gordon, LLC
webmaster@garymgordon.com
Certified Web Developer ::
Application Programmer
 
The include path is in @INC.

To include a folder that is not ther by default:

push @inc "/path/to/pmod";
use pmod;

Then, it'll find it.

Also, you need to look into what methods it exports by default, some methods you have to do:

use pmod qw(method1 method2 ... methodn);

If they are not exported into your namespace by default.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
another way to push the path name into @INC is like this:[tt]
use lib ("/path/to/the/module");[/tt]
and then go on to 'use' the modules in that path. "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top