1FindBin(3pm) Perl Programmers Reference Guide FindBin(3pm)
2
3
4
6 FindBin - Locate directory of original perl script
7
9 use FindBin;
10 use lib "$FindBin::Bin/../lib";
11
12 or
13
14 use FindBin qw($Bin);
15 use lib "$Bin/../lib";
16
18 Locates the full path to the script bin directory to allow the use of
19 paths relative to the bin directory.
20
21 This allows a user to setup a directory tree for some software with
22 directories "<root>/bin" and "<root>/lib", and then the above example
23 will allow the use of modules in the lib directory without knowing
24 where the software tree is installed.
25
26 If perl is invoked using the -e option or the perl script is read from
27 "STDIN" then FindBin sets both $Bin and $RealBin to the current
28 directory.
29
31 $Bin - path to bin directory from where script was invoked
32 $Script - basename of script from which perl was invoked
33 $RealBin - $Bin with all links resolved
34 $RealScript - $Script with all links resolved
35
37 If there are two modules using "FindBin" from different directories
38 under the same interpreter, this won't work. Since "FindBin" uses a
39 "BEGIN" block, it'll be executed only once, and only the first caller
40 will get it right. This is a problem under mod_perl and other
41 persistent Perl environments, where you shouldn't use this module.
42 Which also means that you should avoid using "FindBin" in modules that
43 you plan to put on CPAN. To make sure that "FindBin" will work is to
44 call the "again" function:
45
46 use FindBin;
47 FindBin::again(); # or FindBin->again;
48
49 In former versions of FindBin there was no "again" function. The
50 workaround was to force the "BEGIN" block to be executed again:
51
52 delete $INC{'FindBin.pm'};
53 require FindBin;
54
56 FindBin is supported as part of the core perl distribution. Please
57 submit bug reports at <https://github.com/Perl/perl5/issues>.
58
59 Graham Barr <gbarr@pobox.com> Nick Ing-Simmons <nik@tiuk.ti.com>
60
62 Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved.
63 This program is free software; you can redistribute it and/or modify it
64 under the same terms as Perl itself.
65
66
67
68perl v5.36.0 2022-08-30 FindBin(3pm)