muntfish has asked for the wisdom of the Perl Monks concerning the following question: (files)

Now this is probably a RTFM question, but I have gone through various perldocs and can't find the answer.

I just want to find the filename of the target of a symbolic link. I can tell that something is a symlink (using the -l test) and I can get some info on the target (using stat) or the link itself (using lstat) but these don't tell me the actual name of the target.

I'm sure I'm missing something obvious - please can someone give me a shove in the right direction? Thanks.


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re: Target filename of a symbolic link
by shenme (Priest) on Sep 07, 2004 at 14:21 UTC
    I think 'readlink' is what you are looking for? Find it in perlfunc.

      Duh. Yes, readlink it is. Why didn't I see that? I'm sure I looked at every perlfunc entry with "link" in the name... Thank you.


      s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
        On *nix, perldoc perlfunc | less (or with the appropriate $PAGER setup), and search for link.

        On Win*, if you don't have a useful pager, it's a bit harder...try loading the HTML page and searching that.

        Regardless, there is always perldoc.com: the perlfunc page, or search for perlfunc, or search for link.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

Re: Target filename of a symbolic link
by mrpeabody (Friar) on Sep 07, 2004 at 19:40 UTC
    This is when the "Perl Functions by Category" index near the beginning of perlfunc comes in handy. "I know there's a function to do this file-related (network-related, regex-related, etc) thing, but I don't remember what it's called."

    Functions for filehandles, files, or directories "-*X*", "chdir", "chmod", "chown", "chroot", "fcntl", "glob", "ioctl", "link", "lstat", "mkdir", "open", "opendir", "readlink", "rename", "rmdir", "stat", "symlink", "sysopen", "umask", "unlink", "utime"