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


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

The usage from the SYNOPSIS is when you have a bin and lib sitting next to each other, e.g. in a typical CPAN distribution. In your case, that would be:

use FindBin qw($Bin); use lib "$Bin/flies/lib";

$Bin is the directory where your Perl script started. Have a look at the edge cases in FindBin whether you need FindBin::again or $FindBin::RealBin, but I guess it will already work as given. I apologize for having used a misleading CPAN link in my first post: FindBin is in Perl core.

Replies are listed 'Best First'.
Re^4: Instance of 'use lib' won't accept relative path
by Lady_Aleena (Priest) on Aug 22, 2020 at 15:26 UTC

    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
      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.