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 If perl is invoked as
57
58 perl filename
59
60 and filename does not have executable rights and a program called
61 filename exists in the users $ENV{PATH} which satisfies both -x and -T
62 then FindBin assumes that it was invoked via the $ENV{PATH}.
63
64 Workaround is to invoke perl as
65
66 perl ./filename
67
69 FindBin is supported as part of the core perl distribution. Please send
70 bug reports to <perlbug@perl.org> using the perlbug program included
71 with perl.
72
73 Graham Barr <gbarr@pobox.com> Nick Ing-Simmons <nik@tiuk.ti.com>
74
76 Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved.
77 This program is free software; you can redistribute it and/or modify it
78 under the same terms as Perl itself.
79
80
81
82perl v5.10.1 2009-06-23 FindBin(3pm)