in reply to Best practices for local libraries

>some of my files conflicted with system ones

That's the reason I keep all my own modules within the namespace "Misc";
and the physical location is /home/micha/prog/perl/Misc,
having a symbolic link in /etc/perl/Misc.

I don't know if there's a general preferred way.
But this did work out for me.

Having a unmodified homebrew perl installation on osx darwin here, I just looked the include path up:

~$ perl -e 'print map { "$_\n" } @INC' /usr/local/Cellar/perl/5.26.2/lib/perl5/site_perl/5.26.2/darwin-thread +-multi-2level /usr/local/Cellar/perl/5.26.2/lib/perl5/site_perl/5.26.2 /usr/local/Cellar/perl/5.26.2/lib/perl5/5.26.2/darwin-thread-multi-2le +vel /usr/local/Cellar/perl/5.26.2/lib/perl5/5.26.2 /usr/local/lib/perl5/site_perl/5.26.2
So, I might prepend a BEGIN block and push the local path to @INC.

..
I just looked it up, here's what I did in a script some time before:

BEGIN{ use File::Basename; ($name,$path,$suffix) = fileparse ($0); print "path: $path"; push @INC, "$path/perl"; }

I guess, there I followed the logic: Wherever this script lives, I'm going to store my modules within the same directory.

In each case I'd recommend working with links to your (home) modules directory,
just to keep things more tidy.

And I'm utilizing github for storing backups / revision control.

Finally, into some scripts I copied every module needed, also cpan modules, getting a huge single script.

These are scripts I can execute nearly everywhere, without any cpan installation.

I even built a statically linked perl out of this reason.
hth, Michael

Replies are listed 'Best First'.
Re^2: Best practices for local libraries
by haukex (Archbishop) on Dec 07, 2019 at 10:28 UTC
    So, I might prepend a BEGIN block and push the local path to @INC. I just looked it up, here's what I did in a script some time before: ...

    I'd suggest using the lib pragma (which unshifts instead of pushing) in combination with FindBin instead; $0 can in some cases be unreliable, and the code is shorter. So if there are .pm files in the same path as the script: use FindBin; use lib $FindBin::Bin;.

    Finally, into some scripts I copied every module needed, also cpan modules, getting a huge single script.

    See fatpack and pp, although with some modules they have issues.

      Thanks a lot, that's good news.
      You remember me why I married perl a long time ago ;)