Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

How to get the absolute path of a symbolic link

by ZWcarp (Beadle)
on Jun 20, 2012 at 17:29 UTC ( #977420=perlquestion: print w/ replies, xml ) Need Help??
ZWcarp has asked for the wisdom of the Perl Monks concerning the following question:

In perl, when you use the readlink function on a symbolic link it doesn't seem to work them same as when you use the unix command readlink -m. How do you get the absolute path of a symbolic link in perl ? Is there a way without using additional modules?

Comment on How to get the absolute path of a symbolic link
Re: How to get the absolute path of a symbolic link
by morgon (Deacon) on Jun 20, 2012 at 17:35 UTC
    Use Cwd::abs_path to get an absolute path.

    Cwd is a core-module so you don't need to install anything extra.

    use Cwd qw(abs_path); my $absolute_path = abs_path (readlink $link);

      Just like the previous answer stated, Cwd qw(abs_path) would do the job just as realpath from the same module would do.
      However, one really do not need the readlink function anymore because "..Symbolic links and relative-path components ("." and "..") are resolved to return the canonical pathname.." -- perldoc Cwd.

      use Cwd qw(abs_path realpath); #.... my $absolute_path = abs_path($link); # or ... my $absolute_path = realpath($link);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://977420]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-27 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls