Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by haj (Vicar)
on Aug 21, 2020 at 18:43 UTC ( [id://11120978]=note: print w/replies, xml ) Need Help??


in reply to Instance of 'use lib' won't accept relative path

The libs in use lib don't need to be in PERL5LIB nor in PATH. Relative paths in use lib are not relative to the script itself, but to the current working directory. So either the script itself changed its current working directory, or you're calling it from an unexpected location (e.g. you've symlinked the script but not the library directory).

For the frequent situation where you want to have the libraries relative to the script, FindBin is a convenient solution. Directly from the synopsis:

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

Edit:Now pointing to perldoc instead of CPAN, where a search can give different results.

Replies are listed 'Best First'.
Re^2: Instance of 'use lib' won't accept relative path
by ikegami (Patriarch) on Aug 24, 2020 at 06:11 UTC

    That won't work if you call the script via symlink. You need to use $RealBin.

    use FindBin qw( $RealBin ); use lib "$RealBin/../lib";
Re^2: Instance of 'use lib' won't accept relative path
by Lady_Aleena (Priest) on Aug 22, 2020 at 11:57 UTC

    Is that the actual usage, or does something go in place of the ..? In my case, the script is in $HOME/bin and the modules are in $HOME/bin/flies/lib. How would that change the usage, if there are any changes?

    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

      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.

        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

      BTW, probably you should rethink your layout. A lib shouldn’t be under $HOME/bin/. A better place might be $HOME/lib/. Like /usr/local/bin and /usr/local/lib/. Alternatively you could put the whole stuff under /opt. See also. Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        I used my layout for years, so it is what I'm used to doing. With most of my writing being for my site, I've kept things under one "roof". One of the bigger changes was getting my site work out of my Documents directory, finally, and shedding some of the last vestiges of my time using Windows.

        ../site ../site/files ../site/files/audio ../site/files/css ../site/files/data ../site/files/images ../site/files/lib

        So, I'd been using ../files/lib (when under Documents/www and now just site) as the place where all the modules I wrote went, if they were for my site or not. However, recently I decided to move on from that structure a little bit. So, when I moved the few that really don't belong with my site, I moved them to where the scripts that did use them lived, in this case bin. So now I have...

        ../bin ../bin/files/data ../bin/files/lib

        For me, it makes it easier to work on scripts if their helpers were in the same directory as the script. Maybe one day I will get things together, but for now, this is the way I roll.

        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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found