Reputation: 681
I have a perl script whose path is /scripts/original/ascript.pl
A symbolic link to this script also exists: /scripts/linked/ascript.pl
In ascript.pl, I need the path of where the script was called from (so either /scripts/original or /scripts/linked).
abs_path() always returns the resolved location:
use strict;
use Cwd qw(abs_path);
print abs_path($0); # Always prints /scripts/original/ascript.pl
How can I get the full unresolved path?
Upvotes: 1
Views: 323
Reputation: 40748
You could use Cwd::getcwd()
to get the unresolved path to script. But this has already been implemented in a more robust and general way in FindBin
, so we do not have to reinvent the wheel:
use FindBin;
print '$Bin: ', $FindBin::Bin, "\n";
print '$Script: ', $FindBin::Script, "\n";
Output:
$Bin: /scripts/linked
$Script: ascript.pl
You check out the source of FindBin
here.
Upvotes: 3