in reply to Re: unreal absolute path
in thread unreal absolute path

Not to be obtuse about it, but my whole problem is generating the info for the first line in your solution.

Now that I consider it, this may be more of a unix question than a perl one. If I run the script from inside a given directory, how do I determine where that dir is located? My unix prompt reports the info in the way I'd like to collect it for the script, but it has already travaeresed symlinks to get there. Perhaps I should be asking for something other than the current working dir?

Replies are listed 'Best First'.
Re^3: unreal absolute path
by ikegami (Patriarch) on Nov 28, 2004 at 08:11 UTC
    Sorry for misunderstanding. I tried a few things...
    $ \ls -ldF /home2/ikegami lrwxr-xr-x ... /home2/ikegami@ -> /home3/ikegami $ \ls -ldF /home3/ikegami drwx--x--x ... /home3/ikegami/ $ pwd /home2/ikegami $ perl -e 'print `pwd`' /home3/ikegami $ perl -e 'print `pwd -L`' /home2/ikegami $ perl -e 'chdir "www"; print `pwd -L`' /home3/ikegami/www $ perl -le 'use Cwd; print cwd;' /home3/ikegami $ perl -le 'use Cwd; print getcwd;' /home3/ikegami $ echo $PWD /home2/ikegami $ perl -le 'print $ENV{"PWD"};' /home2/ikegami $ perl -le 'chdir("www"); print $ENV{"PWD"};' /home2/ikegami $ perl -le 'use Cwd qw( chdir ); chdir("www"); print $ENV{"PWD"};' /home2/ikegami/www

    `pwd -L` seems to work, at the cost of creating a child process and running pwd. It stops working if chdir is used, unfortunately.

    If the calling shell provides $ENV{"PWD"}, you save the spawning cost. Of course, it doesn't change if chdir is used.

    ... unless you use the chdir from Cwd everywhere.