Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Page 1 of 2 12 LastLast
Results 1 to 8 of 12
  1. #1
    Jasoco is offline Video Gamer/Collector
    Join Date
    Jun 2001
    Location
    Doylestown PA
    Posts
    499
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #2
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/

  3. #3
    Jasoco is offline Video Gamer/Collector
    Join Date
    Jun 2001
    Location
    Doylestown PA
    Posts
    499
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope. Doesn't work.

    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

  4. #4
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. #5
    Jasoco is offline Video Gamer/Collector
    Join Date
    Jun 2001
    Location
    Doylestown PA
    Posts
    499
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    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

  6. #6
    martinatkinson's Avatar
    martinatkinson is offline Registered User
    Join Date
    Jun 2001
    Location
    Granger, IN, USA
    Posts
    517
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. #7
    Jasoco is offline Video Gamer/Collector
    Join Date
    Jun 2001
    Location
    Doylestown PA
    Posts
    499
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. #8
    Jadey's Avatar
    Jadey is offline sosumi
    Join Date
    Apr 2001
    Location
    CANADA
    Posts
    771
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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";

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Example Perl script - FileMaker to MySQL migration generated by FmPro Migrator
    By dsimpson in forum Software Programming & Web Scripting
    Replies: 0
    Last Post: April 18th, 2003, 03:24 PM
  2. I installed Fink under root and.....
    By Hydroglow in forum Unix & X11
    Replies: 5
    Last Post: November 27th, 2002, 03:57 PM
  3. HOW TO STOP SPAM -- join the fight!
    By GadgetLover in forum Apple News, Rumors & Discussion
    Replies: 11
    Last Post: April 11th, 2002, 02:52 PM
  4. vignette client on mac os x
    By erim in forum Software Programming & Web Scripting
    Replies: 8
    Last Post: July 13th, 2001, 01:14 PM
  5. perl problem - i cannot open a file for writing
    By level42 in forum Mac OS X System & Mac Software
    Replies: 7
    Last Post: June 10th, 2001, 06:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •