Reputation: 2861
I want to get the absolute path of the perl script I executed , for example
my current working directory is /home/Program/A/B and there is a perl script in /home/Program/A/sort.pl
When I under the directory of /home/Program/A/B and I type perl ../sort.pl
, I want to get the
absolute path of sort.pl
which is /home/Program/A/sort.pl
I mean no matter what my current working directory is , I want to get the absolute path of the perl
script is , How to achieve that?
thanks
Upvotes: 3
Views: 4269
Reputation: 817
The Cwd module has a useful function for doing this:
use Cwd qw(abs_path);
print abs_path(__FILE__), "\n";
Upvotes: 4
Reputation: 80384
Here’s what you want:
use FindBin qw($RealScript);
That gives you the full path with all the symlinks fixed.
Upvotes: 7