Perl on Win32, with Apache

R

Regent

I have a Perl-based web site, of which each script must "require" a
commonstuff.pl that simply defines some common subroutines and
constants. If I don't put commonstuff.pl in any of the @INC paths, how
should I efficiently include it in each script, avoiding such lines as

require "d:/wwwroot/cgi-bin/commonstuff.pl";

Of course I also tried the following:

unshift (@INC, "d:/wwwroot/cgi-bin");
require ("commonstuff.pl");

However I hate to do such path-specific things in the many scripts. Thanks!

Regent
 
G

gnu valued customer

hello,
Regent said:
I have a Perl-based web site, of which each script must "require" a
commonstuff.pl that simply defines some common subroutines and
constants. If I don't put commonstuff.pl in any of the @INC paths, how
should I efficiently include it in each script, avoiding such lines as

require "d:/wwwroot/cgi-bin/commonstuff.pl";

Of course I also tried the following:

unshift (@INC, "d:/wwwroot/cgi-bin");
require ("commonstuff.pl");

However I hate to do such path-specific things in the many scripts. Thanks!

Regent

use File::Basename;
chdir(dirname( $0 ));
require("commonstuff.pl");

No hard-coded path here, so it might be what you want.

good luck,
Mark
 
G

gnari

Regent said:
I have a Perl-based web site, of which each script must "require" a
commonstuff.pl that simply defines some common subroutines and
constants. If I don't put commonstuff.pl in any of the @INC paths, how
should I efficiently include it in each script, avoiding such lines as

require "d:/wwwroot/cgi-bin/commonstuff.pl";

Of course I also tried the following:

unshift (@INC, "d:/wwwroot/cgi-bin");
require ("commonstuff.pl");

However I hate to do such path-specific things in the many scripts.
Thanks!

change it into a module Commonstuff.pm and drop it in @INC and
use Commonstuff;

if you are using mod_perl, I think you can have Apache pre-load the module,
so you do not need the use line even
this may not apply on windows. actually, this might not apply outside
of my imagination, as I am too lazy to look it up to confirm

gnari
 
G

gnari

gnu valued customer said:
hello,
Regent said:
I have a Perl-based web site, of which each script must "require" a
commonstuff.pl that simply defines some common subroutines and
constants. If I don't put commonstuff.pl in any of the @INC paths, how
should I efficiently include it in each script, avoiding such lines as

require "d:/wwwroot/cgi-bin/commonstuff.pl";
[snip]

use File::Basename;
chdir(dirname( $0 ));
require("commonstuff.pl");

No hard-coded path here, so it might be what you want.

will not work on all webserver setups, so try it before changing
3000 scripts.

anyways the chdir is disgusting. why not:
use File::Basename;
require(dirname($0) . "commonstuff.pl");

gnari
 
S

sangeetha

Create package file .pm file and place in the current directory. "use
package"
In anotherway, in the configuration file your have specified the
location HTTPROOT(???) directory for the application. So give relative
path from that ROOT in the "require x/y/z/fileame".

Sangetha
 
R

Regent

gnari said:
hello,
I have a Perl-based web site, of which each script must "require" a
commonstuff.pl that simply defines some common subroutines and
constants. If I don't put commonstuff.pl in any of the @INC paths, how
should I efficiently include it in each script, avoiding such lines as

require "d:/wwwroot/cgi-bin/commonstuff.pl";
[snip]


use File::Basename;
chdir(dirname( $0 ));
require("commonstuff.pl");

No hard-coded path here, so it might be what you want.


will not work on all webserver setups, so try it before changing
3000 scripts.

anyways the chdir is disgusting. why not:
use File::Basename;
require(dirname($0) . "commonstuff.pl");

gnari
Yes, that's the solution, except that with -T in the shebang, I must do
something with dirname($0) before concatenating the path with
commonstuff.pl.

Thanks folks!

Regent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top