Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Finding the current directory

by VenROCK (Acolyte)
on Oct 10, 2005 at 15:06 UTC ( #498834=perlquestion: print w/replies, xml ) Need Help??
VenROCK has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, is there a better way to get the current directory in windows than
and what about other OS? Thank You!

2005-10-10 Retitled by planetscape, as per Monastery guidelines
Original title: 'where i am??'

Replies are listed 'Best First'.
Re: Finding the current directory
by polypompholyx (Chaplain) on Oct 10, 2005 at 15:16 UTC
Re: Finding the current directory
by nimdokk (Vicar) on Oct 10, 2005 at 15:07 UTC
    the Cwd module should help.
Re: Finding the current directory
by graff (Chancellor) on Oct 10, 2005 at 22:18 UTC
    Given this snippet:
    $_ = `cd`; chomp; print;
    I gather you are not using any sort of unix-like system, or any unix-style version of the "cd" command ported for use on a windows system.

    In any flavor of unix, a bare "cd" command sets the CWD to your home directory (typically "/home/yourname"), and produces no output on stdout. So doing this within backticks in a perl script will set $_ to an empty string, and have no effect on the script's behavior in any way -- except for using up the time it takes to spawn a shell process, do a useless "cd" command in that process, and then shut down the shell.

    Definitely go with the Cwd module. It's part of the core distribution, and provides uniform behavior on all platforms.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://498834]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2018-01-24 02:36 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (255 votes). Check out past polls.