Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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
$_=`cd`;chomp;print
and what about other OS? Thank You!

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

Comment on Finding the current directory
Download Code
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 polypompholyx (Chaplain) on Oct 10, 2005 at 15:16 UTC
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://498834]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-08-27 09:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (235 votes), past polls