Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get current path to current directory.

Posted on 1998-02-13
3
Medium Priority
?
2,457 Views
Last Modified: 2008-02-01
Just want to know how getting current whole path to current directory, changed in my script with chdir for example...
0
Comment
Question by:steph84
3 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1209757
#!/usr/local/bin/perl

$PATH=`pwd`;
print "$PATH\n";
0
 
LVL 85

Expert Comment

by:ozo
ID: 1209758
Or, if you want to be more portable to different operating systems

use Cwd;
$PATH = cwd();

or, to override chdir to keep PWD up to date

use Cwd 'chdir';
chdir $PATH;
print $ENV{PWD};

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1209759
IMHO, all the built-in things about pwd, cwd, chdir are to be used with extreme care in perl, except you realy know what they are doing.

For example:
  - manipulate the imported environment PWD, usually not what you expect
  - use `pwd` even on platforms where it is not supported (pwd.pl)
Also keep in mind that in a shell $cwd may be differ to `pwd` and both a different to that what  "df ."   reports.

Things go wrong, even with perl :-(
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question