Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Howto set path for local package in a Perl code

by neversaint (Deacon)
on Jun 01, 2006 at 10:22 UTC ( #553018=note: print w/replies, xml ) Need Help??


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

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.......

Replies are listed 'Best First'.
Re^3: Howto set path for local package in a Perl code
by davorg (Chancellor) on Jun 01, 2006 at 10:39 UTC
    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

Re^3: Howto set path for local package in a Perl code
by krisahoch (Deacon) on Jun 01, 2006 at 17:56 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://553018]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2023-12-05 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (26 votes). Check out past polls.

    Notices?