/usr/bin/env perl use strict; use warnings; BEGIN { unshift @INC, '~/perl5/lib/perl5'; } use Excel::Writer::XSLX;
/usr/bin/env perl use strict; use warnings; use Array::Contains; BEGIN { if(contains('--debug', \@ARGV)) { print("Development INC activated\n\n"); unshift @INC, '~/perl5/lib/perl5'; } } use Excel::Writer::XSLX;

Did you try your examples? I don't think so.

Both are missing a shebang (#!) in line 1 and would cause a syntax error. Plus, as shown in Load module from local dir, neither manipulating @INC nor use lib expand the tilde. unshift never should, and use lib doesn't, at least not in my Perl:

/home/alex>cd /tmp/ /tmp>echo 'package Foo;1;' > ~/Foo.pm /tmp>perl -E 'use Foo; say "ok"' Can't locate Foo.pm in @INC (you may need to install the Foo module) ( +@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib +64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /u +sr/share/perl5 .) at -e line 1. BEGIN failed--compilation aborted at -e line 1. /tmp>perl -E 'use lib "~"; use Foo; say "ok"' Can't locate Foo.pm in @INC (you may need to install the Foo module) ( +@INC contains: ~ /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/l +ib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 +/usr/share/perl5 .) at -e line 1. BEGIN failed--compilation aborted at -e line 1. /tmp>perl -E 'use lib "~/."; use Foo; say "ok"' Can't locate Foo.pm in @INC (you may need to install the Foo module) ( +@INC contains: ~/. /usr/local/lib64/perl5 /usr/local/share/perl5 /usr +/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl +5 /usr/share/perl5 .) at -e line 1. BEGIN failed--compilation aborted at -e line 1. /tmp>perl -E 'use lib $ENV{"HOME"}; use Foo; say "ok"' ok /tmp>perl -v This is perl 5, version 22, subversion 2 (v5.22.2) built for x86_64-li +nux-thread-multi Copyright 1987-2015, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. /tmp>

And by the way:

Saying

use lib LIST;

is almost the same as saying

BEGIN { unshift(@INC, LIST) }
(from lib)

Except that newer versions of lib do some additional fancy stuff with architecture-specific directories:

For each directory in LIST (called $dir here) the lib module also checks to see if a directory called $dir/$archname/auto exists. If so the $dir/$archname directory is assumed to be a corresponding architecture specific directory and is added to @INC in front of $dir. lib.pm also checks if directories called $dir/$version and $dir/$version/$archname exist and adds these directories to @INC.

Also, if can be used to conditionally load other modules, including lib:

/tmp>perl -E 'use if -f(qq[$ENV{"HOME"}/Foo.pm]), lib => $ENV{"HOME"}; + use Foo; say "ok"' ok /tmp>

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^2: Load module from local dir by afoken
in thread Load module from local dir by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.