Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get unresolved cwd?

1 view
Skip to first unread message

Yue Chen

unread,
Dec 29, 2009, 4:50:09 AM12/29/09
to Perl Beginners
Hi

As we all know, we can use code such as 'use Cwd; $cwd = getcwd()' to
get current working path. If my current path is a soft link
/this/is/a/link pointing to /this/is/a/realpath, the function 'getcwd'
returns the resolved value of '/this/is/a/realpath'.

I know I can use environment variable '$ENV{PWD}' to get unresolved
value but it is unreliable because this environment variable might
already be changed by the parent process spawning perl. I wonder is
there any kind of official way to do this job?

Thanks in advance.

Randal L. Schwartz

unread,
Dec 29, 2009, 11:36:46 AM12/29/09
to begi...@perl.org
>>>>> "Yue" == Yue Chen <godsa...@gmail.com> writes:

Yue> I know I can use environment variable '$ENV{PWD}' to get unresolved
Yue> value but it is unreliable because this environment variable might
Yue> already be changed by the parent process spawning perl. I wonder is
Yue> there any kind of official way to do this job?

What if there are 100 different "unresolved" paths? Which one do you
want?

mkdir foo
for i in bar{a,b,c,d,e,f,g}{h,i,j,k,l,m,n}{o,p}; do ln -s foo $i; done

do you want baraho, or barclp, or barfho or ...?

And I'm not asking this to be pedantic. I'm asking so that you think
about what you're actually asking for.

If you want to know "how did the user get there", you'll need to have
a trail of what they did some how, which may not be available.

If you just want to know "where am I", then please accept the "resolved" name
as your current location.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Yue Chen

unread,
Dec 29, 2009, 9:46:16 PM12/29/09
to Randal L. Schwartz, begi...@perl.org
Hi Randal

You are right. I can only make my script to get unresolved path by
enforcing it to know how it reaches the unresolved path.

Thank you for the help.

> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
> http://learn.perl.org/
>
>
>

0 new messages