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

Hi , how can you check your current directory ,, I want to check at the begining of my script weather or not I am under
/build
thanks for help

Replies are listed 'Best First'.
Re: current directory
by thelenm (Vicar) on Jul 22, 2002 at 14:24 UTC
    You can use the Cwd module, like this:
    use Cwd; my $dir = cwd;

    -- Mike

    --
    just,my${.02}

Re: current directory
by simeon2000 (Monk) on Jul 22, 2002 at 14:33 UTC
    Mike gave the perfect answer. However, if for some reason you didn't want to load the Cwd module, you could always just my $cwd = `pwd`; or your system's equivalent.

    "Falling in love with map, one block at a time." - simeon2000

Re: current directory
by Abstraction (Friar) on Jul 22, 2002 at 14:34 UTC
    You can also check this:

    $ENV{PWD}

    Update: If you:

    use Cwd qw(chdir);

    Your $ENV{PWD} will be kept up to date.

      Yes, assuming:

      1. That you are using an operating system that populates $ENV{PWD} with the correct answer.
      2. That you haven't executed a chdir anywhere in your code.
        1. That you are using an operating system that populates $ENV{PWD} with the correct answer.
        2. That you haven't executed a chdir anywhere in your code.
        You forgot:
        3. You aren't being lied to by the caller.
        since any program that trusts an env variable is a likely target for a security break-in.

        -- Randal L. Schwartz, Perl hacker

      thanks all