in reply to Curious behavior of Use

Say your module is in /home/geoffleach/src/lib/My/Example.pm, something like this should work:

# from memory, not tested before posting ... BEGIN { unshift @INC, "/home/geoffleach/src/lib"; }; use My::Example; ...

It's important that the BEGIN block is before the use statement.

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Also check out my sisters artwork and my weekly webcomics

Replies are listed 'Best First'.
Re^2: Curious behavior of Use
by ikegami (Patriarch) on Feb 24, 2025 at 16:22 UTC

    That's an incorrect way of writing the following:

    use lib "/home/geoffleach/src/lib"; use My::Example;

    The OP claimed this doesn't work. Your version won't work any better. (It's in fact worse since it doesn't include the related arch dir.)

    (Also, it doesn't make much sense to hardcode absolute paths to library directories. Use PERL5LIB for absolute paths, and use use lib for relative paths.)