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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

including other perl files

Status
Not open for further replies.

Hikeeba

Programmer
Nov 17, 2000
5
US
I'm rather new to perl. I wan to know how to include other perl scripts into my perl script. For example, I have a file called 'website.pl' that has all of my nifty perl subs that I use. Then I write a script in 'newsupdate.pl' and I want to use the subs from the 'website.pl' file.

I'd rather NOT make this a package and just do something like #include <website.pl> ;-) but if I must make it a package let me know.

Thanks,
Joh
 
Unless you have a specific reason for not making it a package, it's pretty easy.

package myPackage;


sub a...

sub b...


1; #It must return true...

then, in your main file, just do:
use myPackage;

and all of your subs will be avalible in the scope of the program. If you need clearer syntax, just let me know. I'm at home now and all of my references are at work...

Good Luck
 
That's cool, actually I like that method because I have to prefix my calls.

myPackage::FuncA;

Is there a way to have FuncA within the scope of the main perl file so you can just

FuncA;

I don't really need it, I like the other method, but Iw as just wondering ;)

John
 
i believr you can use:

require website.pl;


then you should be able to use all your sub routines normally
 
You could Also make them modules and subroutines. Doing that you could keep all of the variable names private and seperate by using 'my var1;' and so on. I do this for parsing the input variables since I do it in every cgi script

Miah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top