in reply to Howto set path for local package in a Perl code

Hard to tell what's wrong in line 10 when all you show us are lines 1-4. Anyway this line
use lib "home/neversaint/MyPerl/src/mypackage.pm";
should read
use lib "/home/neversaint/MyPerl/src"; use mypackage;
The arguments for use lib are paths, not files.

Also, you shouldn't name your modules in all lower case. That's reserved for pragmas.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Howto set path for local package in a Perl code
by neversaint (Deacon) on Jun 01, 2006 at 10:22 UTC
    Dear holli,

    Thanks so much for the reply, however after following your suggestion with this header in mycode.pl
    use strict; use warnings; use lib "/home/neversaint/MyPerl/src"; use MYPACKAGE;
    what I get is this...
    ~/MyPerl/src $ perl -c src/mycode.pl # gives Can't locate MYPACKAGE.pm in @INC (@INC contains: home/neversaint/MyPe +rl/src /home/neversaint/lib/perl5/site_perl/5.8.5/i386-linux-thread-m +ulti/5.8.5/i386-linux-thread-multi
    In MYPACKAGE.pm what I have is this:
    # plain header nothing here... # straight go to the functions.... sub some_func { # do sth; return $soth } 1;
    Although I have no problem at all running mycode.pl in src/ directory : ~/MyPerl $ perl mycode.pl someparam

    Did I still miss anything?

    ---
    neversaint and everlastingly indebted.......
      Can't locate MYPACKAGE.pm in @INC (@INC contains: home/neversaint/MyPerl/src /home/neversaint/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/5.8.5/i386-linux-thread-multi

      That error message still gives the path without the leading slash. Which makes me think that perhaps you haven't edited the file successfully to correct that.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

      neversaint, try this code.
      This is for you script file 'mycode.plx'
      # In script file named: mycode.plx use strict; use warnings; use diagnostics; # This just gives you more info. use lib '/home/neversaint/MyPerl/src'; use MyPackage; # Now the rest of your code.
      This is for your package file 'MyPackage.pm'
      # In MyPackage.pm package MyPackage; use strict; use warnings; use diagnostics; sub some_function { print("My some function"); }
      Now here is the important part. The use statement, the file name, and the package declaration MUST all be in the same case.
      • Use statement: use MyPackage;
      • File Name: MyPackage.pm
      • Package statement: package MyPackage;
      Kristofer Hoch