Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Curious behavior of Use

by cavac (Prior)
on Feb 24, 2025 at 16:04 UTC ( [id://11164070]=note: print w/replies, xml ) Need Help??


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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11164070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2025-06-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.