Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

@INC from $0

by der (Initiate)
on Jul 24, 2015 at 00:35 UTC ( #1136094=perlquestion: print w/replies, xml ) Need Help??

der has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for a CPAN module that will put the directory from $0 onto @INC. It's a trivial bit of code, yes, but I hate to replicate it all over the place. (And of course, I can't re-use that code without getting something onto @INC first (the admins at most shops won't let me put stuff into system directories).)

I'm okay with mandating a directory on every user's PATH, but I like to keep things as simple as possible and not rely on trying to get PERL5LIB set in every user's env. My philosophy is that if you can run the program, it should just run.

Does some form of this exist, or some other elegant solution I've overlooked?

Replies are listed 'Best First'.
Re: @INC from $0 (FindLib)
by tye (Sage) on Jul 24, 2015 at 02:17 UTC

    We arrange to have File::FindLib installed (it is just 1 file) into a default include directory of the Perl we use and use it to bootstrap the rest.

    - tye        

      Yup, that's the ticket. Thanks!
Re: @INC from $0
by dave_the_m (Monsignor) on Jul 24, 2015 at 08:59 UTC
    This is what the core module FindBin is designed for:
    use FindBin; use lib $FindBin::Bin;


Re: @INC from $0
by BrowserUk (Patriarch) on Jul 24, 2015 at 01:14 UTC
      use happens at BEGIN time, so that won't work  Empty compile time value given to use lib
Re: @INC from $0
by Anonymous Monk on Jul 24, 2015 at 01:47 UTC

    use File::Spec; use File::Basename(); use lib File::Basename::dirname( File::Spec->rel2abs( $0 ) ).'/lib';

    Here are hints

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1136094]
Approved by stevieb
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-01-26 17:53 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.