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

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, are in the same directory. Yet, when executed the script still says it cannot locate

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


    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;
    #!/usr/bin/perl use Cwd; use lib Cwd::cwd; use basedat;
    #!/usr/bin/perl use Cwd 'cwd'; use lib cwd; use basedat;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2019-01-20 07:01 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (345 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!