in reply to Re: Figuring out the environment
in thread Figuring out the environment

Ok correction, I was able to get a list of environment variables, there's a copy lag from one server to the main webserver so unaware of this I thought it didn't work. However the list of variables does not contain one for current directory or PWD.

$cwd = $ENV{'PWD'};

I tried this code with no luck, this time I made sure the page updated :) But more importantly why wouldn't I have this environment variable, and is there another way to get the current directory?

Replies are listed 'Best First'.
Re: Re: Re: Figuring out the environment
by kelan (Deacon) on Sep 25, 2002 at 16:40 UTC
    Do you know what OS the server is running? AFAIK, Microsoft OS's don't have an environment variable for the current directory. However, the Cwd module, which is one of the Perl core modules, provides a function called cwd which returns the current working directory.
    use Cwd; $cwd = cwd(); print "My directory is $cwd\n";

    kelan


    Yak it up with Fullscreen ChatBox

      Thanks alot kelan! I wasn't including the Cwd module (use Cwd;) I now just need to change the directory to another server's folder (probably a chdir will do it), so that helped tremendously!
Re: Re: Re: Figuring out the environment
by Mr. Muskrat (Canon) on Sep 25, 2002 at 16:39 UTC
    IMO, CWD is the most portable solution for finding the current working directory.