I am getting the perl script location using $FindBin::RealBin
. Now I have a problem using this.
I am calling a Perl script from one Perl script.
In the caller script, $FindBin::RealBin
is working fine, but in the called Perl script, it is not giving the location.
Am I missing anything?

- 713
- 3
- 11
- 24
-
1Does this work http://perl.active-venture.com/lib/Cwd.html ? – huon Mar 29 '12 at 05:08
-
`$FindBin` is used to find the directory where the Perl script is located. That is different from the current working directory of the Perl process. Which are you really looking for? – Jonathan Leffler Mar 29 '12 at 05:09
-
i want to get the perl script locations only.. how do i get it in the called perl script.. when i use $FindBin::RealBin it is empty. anyother way to get it? – siri Mar 29 '12 at 05:15
-
possible duplicate of [How do I get the full path to a Perl script that is executing?](http://stackoverflow.com/questions/84932/how-do-i-get-the-full-path-to-a-perl-script-that-is-executing) – eckes Mar 29 '12 at 05:28
3 Answers
This is what I always use:
my ($vol,$script_path, $prog) = File::Spec->splitpath(File::Spec->rel2abs( __FILE__ ));
Check if it works in your case. It should work if you call your inner script as a shell call. I don't know if it would work if you call it with do
.
Some readings about this:
see How do I get the full path to a Perl script that is executing?
FindBin::Bin is broken http://use.perl.org/~Aristotle/journal/33995 (or the google cache http://webcache.googleusercontent.com/search?q=cache:y-5OZsxdTT8J:use.perl.org/~Aristotle/journal/33995)
File::Basename http://perldoc.perl.org/File/Basename.html is more problematic
Hope it helps

- 1
- 1

- 4,151
- 2
- 32
- 50
As you did not provide a full code sample, this is more a guess.
According to the documentation, you need to call
FindBin::again();
as this is a known limitation of FindBin.

- 7,195
- 3
- 43
- 58
If I understand your question, you can use realpath
from Cwd .
$ cat ./mycode
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd;
print "called as '$0'\n";
print "lives in '", Cwd::realpath($0), "'\n";
$ ./mycode
called as './mycode'
lives in '/Users/jrf/Sandbox/mycode'

- 7,426
- 2
- 32
- 36