I was about to point out that you are likely to have an environment variable on hand for this -- e.g. with a bash shell, I can use "$ENV{PWD}" -- but there are some problems with this:
- The name of the %ENV element may vary depending on what shell you use.
- Perl's "chdir" function does NOT update %ENV.
It turns out that jkahn's advice to "use Cwd;" is absolutely right -- and for my own sake, I'm glad to have learned how right it is:
cd /home/graff
perl -e 'use Cwd;
$,=" "; print $ENV{PWD},getcwd,$/;
chdir "/tmp"; print $ENV{PWD},getcwd,$/;'
As the output shown below makes clear, Cwd::getcwd always returns the true current directory:
/home/graff /home/graff
/home/graff /tmp
|