Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^5: Instance of 'use lib' won't accept relative path

by perlfan (Vicar)
on Aug 23, 2020 at 01:12 UTC ( #11121003=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2021-10-24 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?