frinky has asked for the wisdom of the Perl Monks concerning the following question:

Hi fellow monks,

I've got a site which I'm trying to use on two different platforms: Win2000/IIS and Linux/Apache.
Everything succeeds, except for one thing:
require "../config.pl";
What doesn't work is that the IIS can't find the config.pl-file, even though it's got '.' in it's @INC.
The simplest solution would off course be to use an absolute path, but the thing is that I want the config-file to tell me what the abs. path is, not define it in multiple files.

So it looks like IIS-perl (activeperl v5.8) doesn't like the '../'.
Okay, so the solution:
$temp = $ENV{'PATH_TRANSLATED'}; # get full path $temp =~ s|\\|/|g; # convert \ to / (necessary if win) $temp =~ s/\/([^\/]*)\/([^\/]*)$//; # strip the last two parts (filena +me and current folder) to get to '../' push(@INC, $temp); # now it's got the right folder require "config.pl"; # so the '../' isn't needed
But I'm 100% sure there are many better things to do instead of this.
Would someone be so kind to help me with this issue?

Thanx in advance, Paul

Replies are listed 'Best First'.
Re: IIS doesn't like my require statement
by artist (Parson) on Jan 28, 2003 at 04:32 UTC
    I found that there is a bug in IIS-Perl that CGI Scripts Must Use Full Directory Path and explained here too..

    Artist

      WAAH!
      Once again: microsoft sucks!
      Checking the links you gave me, I noticed from the support.microsoft-page that they forgot to do some work:

      STATUS Microsoft has confirmed this to be a problem in Microsoft Internet Information Server version 1.0. We are researching this problem and will post new information here as it becomes available.
      Last Reviewed: 5/1/1999

      So after 4 years they still haven't fixed it???
        "Hey, use ASP(\.NET)? and you wouldn't have such problems, eh?" (Ie why would they care about a competing technology.)

        Makeshifts last the longest.

      That bug is in IIS version 1.0 (circa 1999) though. Surely it was fixed in later versions?

      Hmmm, I suppose this is Microshaft we're talking about though.

        Yeah, they had to have fixed it by now.

        I still want to hear what happens if you try '\' instead of '/'.

        ibanix

        $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
Re: IIS doesn't like my require statement
by ibanix (Hermit) on Jan 28, 2003 at 04:11 UTC
    Considering that Win32 uses "\" as the directory delimeter, have you tried require "..\config.pl" ?

    Update: Right, so as other people have mentioned, that should be "..\\config.pl" or '..\config.pl'. :-)

    Cheers,
    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
      Well, haven't tried it, but one good thing abou IIS is that it has no problems using either 'C:\temp\' or 'C:/temp/' Thanx anyway!

      Ack! Using \ instead of / will not work!

      "..\configure.pl" will be interpreted by Perl as "..nfigure.pl". Double quoted literal paths in Perl are never separated by just "\" even on Win32, even under IIS.

      Update: I just knew I was going to be corrected. Lesson learned. Never say never. Or at least be very specific.

      --
      Grant me the wisdom to shut my mouth when I don't know what I'm talking about.

        You can use both / and \ as a path separator in Perl programs on Win32. The only important thing to remember is that in string literals \ char has special meaning (it is an escape char) and it must be doubled to get single \ char. I.e
        # ok my $path = "dir/file.txt"; # not ok my $path = "dir\file.txt"; # ok my $path = "dir\\file.txt"; # also ok - in single quoted strings only sequences \' and \\ are spec +ial my $path = 'dir\file.txt';
        Of course it is Win32 specific and it is just easier to always use / as a path separator what is more portable. Or even use File::Spec what is the most portable way to create filepaths from components:
        use File::Spec; my $path = File::Spec->catfile(qw(dir file.txt));

        Update: Fixed mismatched quotes. Thanks to Ionizor who noticed it.

        --
        Ilya Martynov, ilya@iponweb.net
        CTO IPonWEB (UK) Ltd
        Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
        Personal website - http://martynov.org

Re: IIS doesn't like my require statement
by Mr. Muskrat (Canon) on Jan 28, 2003 at 15:38 UTC