|
#1
| ||||
| ||||
| Perl: How do I "Require" or "Include" another perl script file? Say I have this one Perl file (page.pl) and I have a separate Perl file (subs.pl) that I want to call Subroutines in. I'd keep the Subs in the subs.pl file and from my other PL file I would call the subroutine. But how do I "Require" or "Include" the "subs.pl" file? This is the only thing holding me from a total site redesign.
__________________ Confucious Say: Jasoco, change your gosh darn SIGNATURE! it's been like that forever! Never disobey Confucious. Jasoco.net - GeekPub Forums |
|
#2
| ||||
| ||||
| Hello! I am just learning CGI so I do not know if this is right but I think all you have to do is put the following line of code into your file underneath your #!/usr/bin/perl line: Code: require "subs.pl"; Have a great day! Albert
__________________ iWorship — Worship software for your Mac Free public beta available! http://www.renovatiosw.com/ |
|
#3
| ||||
| ||||
| Nope. Doesn't work. Quote:
test.pl Code: use CGI; #!/usr/bin/perl require "settings.pl"; print "Content-type: text/html\n\n"; &TestSub; Code: use CGI;
#!/usr/bin/perl
Sub TestSub {
print "Hello!";
}
__________________ Confucious Say: Jasoco, change your gosh darn SIGNATURE! it's been like that forever! Never disobey Confucious. Jasoco.net - GeekPub Forums |
|
#4
| ||||
| ||||
| Hello! Is the file "settings.pl" in the same directory as your main CGI script? It will need to be. If this does not work try using the absolute path to "settings.pl" Let me know what happens! Albert
__________________ iWorship — Worship software for your Mac Free public beta available! http://www.renovatiosw.com/ |
|
#5
| ||||
| ||||
| The Settings file is in the same directory as the Test file. The error page seems to imply the program is looking in its own directory for the files so I tired an absolute path (D:/Inetpub/jasoco/cgi-bin/settings.pl) Which seems to get passed THAT, but now I have a whole new error. Quote:
Am I doing the Sub wrong? Or what? This whole Require part is the ONLY thing keeping me from advancing my site further and I've been racking my brain trying to figure it out!
__________________ Confucious Say: Jasoco, change your gosh darn SIGNATURE! it's been like that forever! Never disobey Confucious. Jasoco.net - GeekPub Forums |
|
#6
| ||||
| ||||
| Hello! Hmmm, looks like my code only works if the contents of your settings.pl file are defining variables, for example, this is a clip out of one of my scripts: # path to template file $template_file="template.html"; And then in your main file you could do something like: require "config.pl"; #program start $top_page=top_page($template_file); $bottom_page=bottom_page($template_file); Other then that I do not know, I am just starting to learn Perl so I guess I was not much help. Have a great day! Albert
__________________ iWorship — Worship software for your Mac Free public beta available! http://www.renovatiosw.com/ |
|
#7
| ||||
| ||||
| Don't feel bad. You're the third person to try and help me with Requiring. I can't seem to find info anywhere. Noone seems to know how to do it the way I need it done. Hmmm Well, I guess I'll look on Perl.com and CPAN again later. If they don't help, can anyone recommend a Perl book? I wonder if my server supports PHP...? Anyone have a way I can test? I don't own the server. The only way I know I can do Perl is that I put a file up and ran it. When it worked, I knew. But I need a sample PHP file I can upload and try. My host didn't tell me anything about what I can do and what I can't.
__________________ Confucious Say: Jasoco, change your gosh darn SIGNATURE! it's been like that forever! Never disobey Confucious. Jasoco.net - GeekPub Forums |
|
#8
| ||||
| ||||
| I've never had to work with CGI on NT, so don't know if this will help. Try using the http path to the script for the require, like: require "http://www.domain.ca/cgi-bin/settings.pl"; |
![]() |
| Thread Tools | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Example Perl script - FileMaker to MySQL migration generated by FmPro Migrator | dsimpson | Software Programming & Web Scripting | 0 | April 18th, 2003 03:24 PM |
| I installed Fink under root and..... | Hydroglow | Unix & X11 | 5 | November 27th, 2002 03:57 PM |
| HOW TO STOP SPAM -- join the fight! | GadgetLover | Apple News, Rumors & Discussion | 11 | April 11th, 2002 02:52 PM |
| vignette client on mac os x | erim | Software Programming & Web Scripting | 8 | July 13th, 2001 01:14 PM |
| perl problem - i cannot open a file for writing | level42 | Mac OS X System & Mac Software | 7 | June 10th, 2001 06:33 PM |