Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

@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 (Prior) 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 (Pope) 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
Node Status?
node history
Node Type: perlquestion [id://1136094]
Approved by stevieb
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-07-21 11:38 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (448 votes). Check out past polls.