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!

How do i include perl files together?

Status
Not open for further replies.

adamf

Technical User
Mar 7, 2002
51
GB
Hi,

I have wrote a large perl function in a file function.pl

I would like to call this function from many different other perl programs but i dont want to paste a copy of the function into every file.

I just need something similar to C's #include

Thanks
 
If the perl file's directory location is in the @INC path information, you can just use:

require "function.pl";

If it isn't, use:

require "x:/path/to/file/function.pl"; # x is the drive letter if this is on an NT machine.

If you don't know what paths are set in the @INC, run this little program from the command line:

#! /usr/bin/perl

print "@INC";
 
Make sure that the last line of the "required" file looks like this:
Code:
1;
When perl requires a file, it wants a "true" value returned, otherwise it throws an error. The 1 in the last statement is the same as "true", and will be returned when the file is "required". Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top