Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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:
/users/<myusername>/perl/Tk-DKW-0.03

I ran the make file. It put the module files at:
Tk-DKW-0.03/blib/lib/Tk

I went to the example directory:
Tk-DKW-0.03/examples

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 ./menustrip.pl Can't locate Tk/Menustrip.pm 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 CheckBox.pm* 12K Menustrip.pm* 4.0K ChildNotification.pm* 4.0K ProgressIndicator.pm* 60K Columns.pm* 4.0K Signals.pm* 12K ComboEntry.pm* 16K SplitFrame.pm* 8.0K CornerBox.pm* 8.0K TabbedForm.pm* 20K DockFrame.pm 16K TabFrame.pm* 28K IconCanvas.pm* 12K TableEdit.pm*

I dont understand what I am doing wrong.

Comment on Problem understanding how to use modules
Select or Download Code
Re: Problem understanding how to use modules
by kennethk (Monsignor) 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/Menustrip.pm in the directories listed in @INC, not Menustrip.pm. 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 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/Menustrip.pm, 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/checkbox.pl
    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 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 bart (Canon) on Nov 19, 2013 at 22:33 UTC
    I ran the make file. It put the module files at:

    Tk-DKW-0.03/blib/lib/Tk

    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 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:
    ~/lib

    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

    --Chris

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1063388]
Approved by Corion
help
Chatterbox?
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: (9)
As of 2014-12-22 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls