Lauren wrote:

>there is another member on this list pointed me a more graceful way,

use lib '/path/..';
That's a good one, too - note, you do want to use an absolute path in there
(and elsewhere) if you're writing this in a script.  Something folks often
misunderstand is that the script is run relative to the current dir, not
the dir where the script resides.  That is, I keep my scripts in
/usr/local/bin, so if I have a /home/andy/perl_lib full of my modules, I'd
want to
use lib '/home/andy/perl_lib';

In the previous command line examples:
$ cd /home/andy
$ perl -e 'use test::mytest; mytest::hello()'
hello
$ cd /tmp
$ perl -e 'use test::mytest; mytest::hello()'
Can't locate test/mytest.pm in @INC (@INC contains:
/gov/ecf/lib/perl5/5.8.8/x86_64-linux /gov/ecf/lib/perl5/5.8.8
/gov/ecf/lib/perl5/site_perl/5.8.8/x86_64-linux
/gov/ecf/lib/perl5/site_perl/5.8.8 /gov/ecf/lib/perl5/site_perl .) at -e
line 1.
BEGIN failed--compilation aborted at -e line 1.

though the absolute path works
$ cd /tmp
$ perl -e 'use lib "/home/andy/test"; use test::mytest; mytest::hello()'
hello

In the spirit of Perl's TMTOWTDI, if you have your own set of modules
somewhere, you can set an ENV var PERL5LIB
$ cd /tmp
$ PERL5LIB=/home/andytest perl -e 'use test::mytest; mytest::hello()'
hello

put that in your .bashrc file and all your modules will be available.
Remember though, cron jobs don't get your .bashrc env.


On Thu, Jul 26, 2018 at 9:35 PM, Kent Fredric <kentfred...@gmail.com> wrote:

> On 27 July 2018 at 05:21, Andy Bach <afb...@gmail.com> wrote:
> >
> > or, as Perl treats the "::" as a path denoter:
> > $ perl -e 'use test::mytest; mytest::hello()'
> > hello
> >
> > or:
> > $ perl -mtest::mytest -e 'mytest::hello()'
> > hello
> >
> > find ./test/mytest.pm via @INC's "."
>
>
> Note: neither of those examples work on Perl 5.26 or greater, as those
> examples rely on "." being in @INC, which it no longer is.
>
> To resolve, your examples either need a "-I." in them, or
> alternatively, just use that format and call it like:
>
> perl -Itest -Mmytest -e "mytest::hello()"
>
> ( There's a workaround available that globally returns '.' to @INC,
> but its gonna be gone in 5.30 or so )
>
>
> --
> Kent
>
> KENTNL - https://metacpan.org/author/KENTNL
>



-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk

Reply via email to