http://qs321.pair.com?node_id=11120996


in reply to Re^3: Instance of 'use lib' won't accept relative path
in thread Instance of 'use lib' won't accept relative path

My brain took a vacation, I read the description several times and didn't get it. Also, both links have the same description, so that is okay. Thank you for the clarity. Have a nice day!

My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^5: Instance of 'use lib' won't accept relative path
by perlfan (Vicar) on Aug 23, 2020 at 01:12 UTC
    FindBin allows you to retain the flexibility of the relatives paths, with the additional benefits of absolute paths. FindBin simply figures out the precise location of the script and allows you to do things like use lib during run time. Managing PERL5LIB can be cumbersome, particular if you are distributing a Perl program that can be put anywhere on someone's system. FindBin allows you to assume the location of libraries with respect to the Binary (your script). This allows you to reason about them absolutely with the flexibility of not knowing where your script is located. What's the alternative? Doing what you've done, setting PERL5LIB explicitly. FindBin would allow you to never have to set this explicitly again (or if you were distributing your code, make your users set PERL5LIB).
    use FindBin; use lib "$FindBin::Bin/../lib";

    This might make sense if you consider the standard layout of some code:

    /path/to/my/bin/myscript.pl /path/to/my/lib/Awesome.pm

    In that case,

    use FindBin; use lib "$FindBin::Bin/../lib";

    Is equivalent to:

    use FindBin; use lib "/path/to/my/bin/../lib";

    Or effectively,

    use FindBin; use lib "/path/to/my/lib";

    This might also make more sense and seem more useful when you also are calling myscript.pl by virtual of /path/to/my/bin being in your PATH.