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

Problem understanding how to use modules

by texan4ever (Initiate)
on Nov 19, 2013 at 21:05 UTC ( #1063388=perlquestion: print w/ replies, xml ) Need Help??
texan4ever has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to use a module I downloaded from CPAN. I am on a unix system where I dont have root permissions. So the CPAN module will have to go in my home directory.

I untarred the CPAN module here:

I ran the make file. It put the module files at:

I went to the example directory:

Then I edited one of the examples and put a use statement at the top:
#! /usr/bin/perl use lib "/users/<myusername>/perl/Tk-DKW-0.03/blib/Tk"; use Tk::Menustrip;
I then get this error:
(attocs951:examples)#482 ./ Can't locate Tk/ in @INC (@INC contains: "/users/<myuserna +me>/perl/Tk-DKW-0.03/blib/lib/Tk /usr/lib64/perl5/5.8.5/x86_64-linux- +thread-multi /usr/lib/perl5/5.8.5 /usr/lib64/perl5/site_perl/5.8.5/x8 +6_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.8.4/x86_64-linux +-thread-multi . . . . .

If I do a ls of the directory I see the modules:
ls /users/<myusername>/perl/Tk-DKW-0.03/blib/lib/Tk total 208K 4.0K* 12K* 4.0K* 4.0K* 60K* 4.0K* 12K* 16K* 8.0K* 8.0K* 20K 16K* 28K* 12K*

I dont understand what I am doing wrong.

Comment on Problem understanding how to use modules
Select or Download Code
Replies are listed 'Best First'.
Re: Problem understanding how to use modules
by daxim (Chaplain) on Nov 19, 2013 at 21:22 UTC
    use lib "/users/<myusername>/perl/Tk-DKW-0.03/blib"; is correct. Perl wants to load Tk/, so the directory name must end in blib, not blib/Tk.

    Better solution: don't edit the example and simply set the include path from the commandline:

    $ cd /users/<myusername>/perl/Tk-DKW-0.03 $ perl -Mblib examples/
    See blib.

    Update: this half-installed directory setup is only useful for testing. If you want to use Tk-DKW productively, you must install the distribution. local::lib helps you to set up the necessary environment variables so that the make install will target your home directory, not the system location where you have no write permission.

Re: Problem understanding how to use modules
by bart (Canon) on Nov 19, 2013 at 22:33 UTC
    I ran the make file. It put the module files at:


    And that's where you left it.

    You ran the makefile. But you didn't install it. That's why the module is in such a weird place.

    It was never the idea to have a separate file tree for every module you install. It was the intention to have at most a few roots containing the modules you need. If you want to have the module under your home directory, then install it there. local::lib might be a handy too for it.

Re: Problem understanding how to use modules
by kennethk (Abbot) on Nov 19, 2013 at 21:17 UTC
    I think you mean
    use lib "/users/<myusername>/perl/Tk-DKW-0.03/blib/lib";
    The use Tk::Menustrip; looks for Tk/ in the directories listed in @INC, not See require, whose mechanism underlies use.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Problem understanding how to use modules
by Anonymous Monk on Nov 19, 2013 at 21:36 UTC

    I had tried both blib/lib/Tk and blib/lib. I then noticed with one configuration it complained about not finding Tk. So then I changed the #! /usr/bin/perl statement at the top of the example to what I ususally use on this system:

    eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' & eval 'exec perl -S $0 $argv:q' if 0;

    then it worked

Re: Problem understanding how to use modules
by taint (Chaplain) on Nov 20, 2013 at 06:47 UTC
    Somewhat along the lines of bart's comment;

    If I were you. I'd create a folder in your Home dir, along the lines of:

    Then you can unpack your modules into a temp folder, and

    cd /tmp/ModuleName perl Makefile.PL make make test make install PREFIX=~/lib
    Some suggest that you should indicate PREFIX= when you issue perl Makefile.PL eg;
    perl Makefile.PL PREFIX=~/lib
    But I've never had any issues simply issuing it during the make install process.

    Best wishes


    OH. One more thing. Do remember to include the lib dir in your programs (@INC) (Perl scripts), eg;

    use lib ('~/lib');

    #!/usr/bin/perl -Tw
    use Perl::Always or die;
    my $perl_version = (5.12.5);
    print $perl_version;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-11-26 20:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (707 votes), past polls