Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Undefined import name priority issue?

by afoken (Chancellor)
on Apr 08, 2025 at 08:05 UTC ( [id://11164626]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Undefined import name priority issue?
in thread Undefined import name priority issue?

The issue seems to be the existance of a file in mylib with name 'json.pm'

No, half of the issue is that you are doing this:

use lib 'mylib'; use mylib::json;

You add the "mylib" directory to the module search path (@INC). In that case, your module should be simply named json and not mylib::json. If you want to load it as mylib::json, don't add the "mylib" directory to @INC, but the directory containing the "mylib" directory (i.e. "."). Older perls already include "." in @INC, that's why it probably works at all.

The second part of the issue is that your filesystem is not case sensitive. Do you see any difference between json and JSON? I see four different bits, but your filesystem does not. So when perl attempts to load "JSON.pm" containing the JSON package, it is fed "json.pm" containing the mylib::json package instead.

Alexander

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

Replies are listed 'Best First'.
Re^4: Undefined import name priority issue?
by sectokia (Friar) on Apr 08, 2025 at 21:56 UTC

    Thanks: that is it exactly... should not have "use lib 'mylib';" at all, isn't needed because I want mylib.pm to reference mylib::json.

      You shouldn't have used use mylib; if you use use mylib::json; and if the module uses package mylib::json;, correct.

      You shouldn't have used use lib in modules. If you got that far, Perl already knows where modules can be found.

      You shouldn't have used use lib '.'; because the current work directory isn't guaranteed to be the script's directory. You should be using

      use FindBin qw( $RealBin ); use lib $RealBin;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2026-03-07 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.