# test-> a.pl
my $file = '/home/joe/test'; if ( -f $file && -l $file ) { print readlink( $file ) ; }
how to get absolute path for symlink file?
Cwd provides such abs_path functions .
#!/usr/bin/perl -w use Cwd 'abs_path'; my $file='/home/joe/test'; if( -f $file && -l $file ) { print abs_path($file); }
if you use File :: Spec rel2abs along with readlink, you will get the paragraph path even if it is a symbolic link to another symbolic link
use File::Spec; $path = File::Spec->rel2abs( readlink($file) ) ;
, . .
my $good = \`readlink -f $0\`;