image
image

Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old February 13th, 2002, 02:19 PM
Jasoco's Avatar
Video Gamer/Collector
 
Join Date: Jun 2001
Location: Doylestown PA
Posts: 499
Thanks: 0
Thanked 0 Times in 0 Posts
Jasoco is on a distinguished road
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
Reply With Quote
  #2  
Old February 16th, 2002, 08:46 PM
martinatkinson's Avatar
Registered User
 
Join Date: Jun 2001
Location: Granger, IN, USA
Posts: 517
Thanks: 0
Thanked 0 Times in 0 Posts
martinatkinson is on a distinguished road
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";
Let me know if this works.

Have a great day!

Albert
__________________
iWorship — Worship software for your Mac
Free public beta available!
http://www.renovatiosw.com/
Reply With Quote
  #3  
Old February 18th, 2002, 08:20 PM
Jasoco's Avatar
Video Gamer/Collector
 
Join Date: Jun 2001
Location: Doylestown PA
Posts: 499
Thanks: 0
Thanked 0 Times in 0 Posts
Jasoco is on a distinguished road
Nope. Doesn't work.

Quote:
CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

Can't locate settings.pl in @INC (@INC contains: D:/activeperl/lib D:/activeperl/site/lib .) at D:\Inetpub\jasoco\cgi-bin\test.pl line 4.
Seems the test files I created aren't written right I guess?

test.pl
Code:
use CGI;
#!/usr/bin/perl

require "settings.pl";

print "Content-type: text/html\n\n";

&TestSub;
settings.pl
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
Reply With Quote
  #4  
Old February 18th, 2002, 08:23 PM
martinatkinson's Avatar
Registered User
 
Join Date: Jun 2001
Location: Granger, IN, USA
Posts: 517
Thanks: 0
Thanked 0 Times in 0 Posts
martinatkinson is on a distinguished road
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/
Reply With Quote
  #5  
Old February 18th, 2002, 08:29 PM
Jasoco's Avatar
Video Gamer/Collector
 
Join Date: Jun 2001
Location: Doylestown PA
Posts: 499
Thanks: 0
Thanked 0 Times in 0 Posts
Jasoco is on a distinguished road
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:
CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

syntax error at D:/Inetpub/jasoco/cgi-bin/settings.pl line 6, near "}"
I seem to have it Requiring right, but now I have a problem with the Required files code.

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
Reply With Quote
  #6  
Old February 18th, 2002, 08:53 PM
martinatkinson's Avatar
Registered User
 
Join Date: Jun 2001
Location: Granger, IN, USA
Posts: 517
Thanks: 0
Thanked 0 Times in 0 Posts
martinatkinson is on a distinguished road
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/
Reply With Quote
  #7  
Old February 18th, 2002, 09:16 PM
Jasoco's Avatar
Video Gamer/Collector
 
Join Date: Jun 2001
Location: Doylestown PA
Posts: 499
Thanks: 0
Thanked 0 Times in 0 Posts
Jasoco is on a distinguished road
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
Reply With Quote
  #8  
Old February 18th, 2002, 09:59 PM
Jadey's Avatar
sosumi
 
Join Date: Apr 2001
Location: CANADA
Posts: 771
Thanks: 0
Thanked 0 Times in 0 Posts
Jadey is on a distinguished road
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";
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump

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


All times are GMT -5. The time now is 11:34 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.