Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
more useful options
 
PerlMonks  

Re: Getting current directory

by oakley (Scribe)
on Feb 09, 2001 at 17:51 UTC ( [id://57440]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Getting current directory

To get the current working directory, you could use:

$currdir = $ENV{PWD};

or

$currdir = $0; <-- (gives full execution path AND program name though)

- oakley
Embracing insanity - one twitch at a time >:)

Replies are listed 'Best First'.
Re: Re: Getting current directory
by chromatic (Archbishop) on Feb 09, 2001 at 18:24 UTC
    Whoa, careful with that advice:
    print $ENV{PWD}, "\n"; chdir('perl'); print $ENV{PWD}, "\n"; print `ls`;
    Yeah, I wouldn't normally use the backticks there, but it proves my point. Also, $0 is spoofable. Cwd is a more reliable solution.

    Update: You can spoof $0 by using symlinks, at least if your OS supports them.

      Unlike argv[0] in C, $0 in Perl is not spoofable. See FindBin is broken (RE: How do I get the full path to the script executing?) for more details.

      But $0 is certainly inappropriate for getting the full path to "the current working directory" or "where the script was called from" (though I could see misinterpretting this last phrase to mean the full path to the script). $0 often tells you the full path to where the script resides.

              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://57440]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.