Gossamer Forum
Home : General : Perl Programming :

re: HELP in calling other directories in CGI

Quote Reply
re: HELP in calling other directories in CGI
I'm a CGI novice, and this may be a dumb question, but how (can) I pull in a subroutine from perl file that is external to the running script. That is, say my directory structure is:

cgi-bin -> DBman -> automobiles
-> boats
-> toothbrushes

Now, I'm running separate versions of DBman in each of those three directories, for simplicity, because they each have their own configuration files, cgi files, auth files, etc. But all three databases use the same masthead at the top of the page -- a rather involved and lengthy rollover sitemap. I've managed to write an external file -- sitemap.pl -- that can be called into the DBman html file (kinda like a perl SSI call). Works fine. Only problem is, it has to be in the same directory as the DBman html file because I'm too stupid to figure out how to word the script call to look outside of the (e.g.) 'automobiles' directory. This is what my CGI SSI call looks like, and it works fine:

sub my_header {
### WE MOVED THE HEADER TO AN EXTERNAL FILE ########
require 'sitemap.pl';
&main;
####################################
}

But, I want to move that file sitemap.pl up to a parent directory, like into the main cgi-bin directory. Why? Because I plan numerous additions to the sitemap, and it would be so convenient if I could just edit that one sitemap.pl file and have it automatically read into all of the individual directories, rather than having to edit each and every DBman html file.

I've been to numerous CGI tutorial sites. None of them mention calling subroutines from remote sources (even if those sources are still within the cgi-bin directory structure). How do I get the perl file to look in a different (non subservient) directory for an auxilary script file (subroutine). Or is this just not possible?

Any help would be greatly greatly appreciated.

--- psbarb


Quote Reply
Re: re: HELP in calling other directories in CGI In reply to
require "/path/to/require.pl";

Wasn't too hard was it Smile

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: re: HELP in calling other directories in CGI In reply to
My God. That works.
Thanks, Paul. I knew it had to be something incredibly infantile. The hardest thing about these script languages (CGI, Javascript, ASP) is the syntax. And the tutorials out there very often skip over what, to them, seems to be obvious. I had tried putting in the entire path, but I was using the URL, which didn't work. But the server path does work.

Bless you.
--- psbarb