Perl on Win32, with Apache

Discussion in 'Perl Misc' started by Regent, Mar 5, 2004.

  1. Regent

    Regent Guest

    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
     
    Regent, Mar 5, 2004
    #1
    1. Advertising

  2. hello,
    "Regent" <> wrote in message
    news:c29c2d$1pkd$99.com...
    > 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
     
    gnu valued customer, Mar 5, 2004
    #2
    1. Advertising

  3. Regent

    gnari Guest

    "Regent" <> wrote in message
    news:c29c2d$1pkd$99.com...
    > 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
     
    gnari, Mar 5, 2004
    #3
  4. Regent

    gnari Guest

    "gnu valued customer" <> wrote in message
    news:5WW1c.62000$...
    > hello,
    > "Regent" <> wrote in message
    > news:c29c2d$1pkd$99.com...
    > > 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
     
    gnari, Mar 5, 2004
    #4
  5. Regent

    sangeetha Guest

    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

    Regent <> wrote in message news:<c29c2d$1pkd$99.com>...
    > 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
     
    sangeetha, Mar 5, 2004
    #5
  6. Regent

    Regent Guest

    gnari wrote:

    > "gnu valued customer" <> wrote in message
    > news:5WW1c.62000$...
    >
    >>hello,
    >>"Regent" <> wrote in message
    >>news:c29c2d$1pkd$99.com...
    >>
    >>>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
     
    Regent, Mar 6, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The Poor
    Replies:
    2
    Views:
    237
    Gregory Toomey
    Sep 27, 2003
  2. Kostas Hatzikokolakis

    Use perl in apache without #!/path/to/perl

    Kostas Hatzikokolakis, Oct 18, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    164
    Ron Savage
    Oct 19, 2003
  3. joe
    Replies:
    8
    Views:
    199
    Matthias Weckman
    Nov 14, 2003
  4. Michael Edmonson

    Win32::SAPI4 question (Win32 events and Perl)

    Michael Edmonson, Feb 28, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    183
    Michael Edmonson
    Feb 28, 2004
  5. PGPS
    Replies:
    10
    Views:
    637
Loading...

Share This Page