Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Surprising behavior of Cwd module on Unix with symlinks

by DrHyde (Prior)
on Feb 08, 2011 at 11:03 UTC ( [id://886920]=note: print w/replies, xml ) Need Help??


in reply to Surprising behavior of Cwd module on Unix with symlinks

FindBin will do what you want:

$ ls -l symlink lrwxrwxrwx 1 david david 22 2011-02-08 10:54 symlink -> foo/bar $ cd symlink $ pwd /home/david/symlink $ ls -l .. drwxr-xr-x 2 david david 4096 2011-02-08 10:54 bar

Note that ls shows us the contents of the parent of the *real* directory that we're in, not the contents of the directory containing the symlink. Symlinks are a bit weird.

$ perl -MFindBin -e 'print "$FindBin::Bin\n"' /home/david/foo/bar

FindBin correctly resolves it, giving us the full path to the directory.

Replies are listed 'Best First'.
Re^2: Surprising behavior of Cwd module on Unix with symlinks
by Anonyrnous Monk (Hermit) on Feb 08, 2011 at 12:26 UTC
    FindBin correctly resolves it, giving us the full path to the directory.

    As far as I understand, the OP wants the opposite, i.e. the respective symlink path being returned (/home/david/symlink in your case), not the target of the symlink, which is more generally aka realpath, and is easier to determine.

    As ikegami pointed out, some other process (usually the shell) needs to keep track of the chdir history to be able to provide the info the OP wants.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://886920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2025-03-21 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (63 votes). Check out past polls.