FindBin(3pm)
πΈ FindBin(3pm) β like, the actual manual page, bestie π
Okay so this is FindBin, straight out of the Perl Programmers Reference Guide (section 3pm, iykyk). Buckle up, it's short but it eats. β¨
β¨ NAME β¨
FindBin β lowkey the module that finds the directory your original Perl script is living in. That's the whole vibe. π
π¦ SYNOPSIS π¦
The main character setup, fr fr:
use FindBin;
use lib "$FindBin::Bin/../lib";
use FindBin qw($Bin);
use lib "$Bin/../lib";
Two ways, same energy. Pick your fave. π
π DESCRIPTION π
So basically FindBin locates the full path to the script's bin directory, which lets you use paths that are relative to that bin directory. Iconic behavior, honestly. π«Ά
Why do you care? Because now a user can set up a directory tree for some software with directories <root>/bin and <root>/lib, and then the example up in SYNOPSIS lets you use modules in the lib directory without knowing where the software tree is installed. No cap, that's the whole point. β¨
π¨ Edge case alert: ifperlis invoked using the-eoption, or the Perl script is read fromSTDIN, thenFindBinsets both$Binand$RealBinto the current directory. Not the script's dir. There is no script. Adjust expectations accordingly. π
π EXPORTABLE VARIABLES π
Here's the squad you can import:
$Binor$Dirβ path to the bin directory from where the script was invoked ποΈ$Scriptβ the basename of the script from whichperlwas invoked π$RealBinor$RealDirβ$Binwith all links resolved π$RealScriptβ$Scriptwith all links resolved π
And if you're feeling greedy (valid), you can use the ALL tag to export every single one of the above together:
use FindBin ':ALL';
All the variables. One tag. Main character energy tbh. π
π KNOWN ISSUES π
Okay bestie, listen, this is the important part, don't skip it. π
If there are two modules using FindBin from different directories under the same interpreter, this won't work. Periodt. Why? Because FindBin uses a BEGIN block, so it'll be executed only once, and only the first caller will get it right. π
This is a problem under mod_perl and other persistent Perl environments β where you shouldn't use this module at all. Which also means you should avoid using FindBin in modules that you plan to put on CPAN. Yeah. That's a real constraint, not a vibe check. π«
The fix? Call the again function to make sure that FindBin will work:
use FindBin;
FindBin::again(); # or FindBin->again;
β Fun lore: in former versions ofFindBinthere was noagainfunction. The workaround was to force theBEGINblock to be executed again:
delete $INC{'FindBin.pm'};
require FindBin;
Ancient technique. Works tho. π§
π AUTHORS π
FindBin is supported as part of the core perl distribution. π
Please submit bug reports at <https://github.com/Perl/perl5/issues> β the maintainers are literally waiting, be nice about it. π«Ά
The actual legends behind it:
- Graham Barr <gbarr@pobox.com>
- Nick Ing-Simmons <nik@tiuk.ti.com>
Two icons. Respect. π
π COPYRIGHT π
Copyright (c) 1995 Graham Barr & Nick Ing-Simmons. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π¦
And that's the page!! You now know more about FindBin than like 90% of people writing Perl, congrats babe πΈ
Signed off with love from perl v5.42.3, dated 2026-11-03 β the FindBin(3pm) girlies stay winning πβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms