Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Cannot find my own modules

by core_dumped (Acolyte)
on Sep 11, 2018 at 17:23 UTC ( #1222145=perlquestion: print w/replies, xml ) Need Help??
core_dumped has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks!

I have been sometime (several years on a pilgrimage) away from larger-than-one-file Perl scripts and I have found problems using my own modules.

I learned the current working directory has been removed from @INC as a default and found a FindBin recipe in some website. However, I don't seem to understand it correctly. Please some advice.

This is my script, which uses my own module called "basedat" (to connect to a database and hide all the ugly details):

#!/usr/bin/perl # Connection to database use FindBin qw($Bin); use basedat "$Bin/basedat"; $dbh = basedat::new(); if (defined($dbh)) { print "connection ok!\n"; }

Both, this script and my module, called basedat.pm, are in the same directory. Yet, when executed the script still says it cannot locate basedat.pm.

Any light you could shed would be greatly appreciated

Replies are listed 'Best First'.
Re: Cannot find my own modules
by haukex (Canon) on Sep 11, 2018 at 17:30 UTC

    Try:

    use FindBin; use lib $FindBin::Bin; use basedat;

    Update - Explanation: use basedat "$Bin/basedat"; is probably not doing what you want because it's just trying to pass the string "$Bin/basedat" to basedat->import() (see use), it's not telling Perl where to actually find the module. To do that, you need to modify @INC, which I'm doing above with FindBin and lib.

      Thank you very much!

      Exactly what I needed to understand

Re: Cannot find my own modules
by Anonymous Monk on Sep 12, 2018 at 03:08 UTC
    #!/usr/bin/perl use lib '.'; use basedat;
    TIMTOWTDI
    #!/usr/bin/perl use Cwd; use lib Cwd::cwd; use basedat;
    TIMTOWTDI
    #!/usr/bin/perl use Cwd 'cwd'; use lib cwd; use basedat;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1222145]
Approved by LanX
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-11-12 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (143 votes). Check out past polls.

    Notices?