Hi,
I was looking up previous posts on how to get the path to a script. It seems the preferred suggestion is
use Cwd qw(abs_path);
my $path = abs_path($0);
However, when I do this, I get the path including the script file itself, e.g. if I run a script
/long/path/to/some/script.plx,
abs_path($0) returns the whole thing and not
/long/path/to/some/ as I expected. So I still have to use a regex to remove the script name, but someone in the old posts said that was looking for trouble.
Is that, uh, intended/normal, or am I doing something wrong?
And as long as I'm at it: Basically, I want to ensure that relative paths containing information the script needs are always correct, even if I call the script from somewhere else by specifying the path, like maybe
.../other/dir/ $ ../../some/script.plx
So I wanted to get the path and then chdir there. Is that the right way to go about it or is there a much easier way? I tend to think too complicated sometimes :-/ I'm on Linux and portability isn't an issue.