Reputation: 3059
I am trying to invoke a script from within a perl script. I can see 2 ways of doing this..
using ./somescript or specifying the full directory path. Neither is ideal, since "./" will only work as long as the invoker cd's into the directory. Full path, is not relative but absolute. Anyway around this? thanks
Upvotes: 0
Views: 383
Reputation: 22421
Use FindBin
module if you want find directory where your original script is, and use Cwd
if you want to find your current working directory.
Upvotes: 1
Reputation: 3059
One way to do this is to determine the directory your script belongs in , and using that How do I get the full path to a Perl script that is executing?
provides 2 ways to accomplish this.
Upvotes: 1
Reputation: 963
To get the full path to the script you're currently executing, you can use either of the following chunks of code from PerlMonks. File::Basename:
#!/usr/bin/perl -w
use strict;
use File::Spec::Functions qw(rel2abs);
use File::Basename;
print dirname(rel2abs($0));
or CWD can be used for this purpose. CWD example:
use Cwd;
my $dir = getcwd;
It should be possible to build up a full path using the base directory, plus your knowledge of the relative placement of the initial script and the second script you'd like to invoke. That way, while you will be using an absolute path to invoke the second script, you're only hardcoding a relative path?
Upvotes: 0