Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Functions not importing when module in folder

by Anonymous Monk
on Mar 25, 2013 at 13:31 UTC ( #1025302=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to re-use some code by using a module, and it seems to work until I try to put it in a folder.

For example, when my the app.pl and My_Module.pm are in the same directory (i.e. /path/to/dir/app.pl and /path/to/dir/My_Module.pm), it works fine when I put use My_Module; in app.pl.

But as soon as I move My_Module.pm to a directory IN the app directory (i.e. /path/to/dir/My_Module_Folder/My_Module.pm), the functions don't seem to import. In app.pl, I am putting use My_Module_Folder::My_Module;, and it compiles fine, but I get an error when I try to use a function from My_Module.

Does anyone have any idea how to fix this? I can move the module file to the app dir, but I would like to keep things organized.

Thanks!

Replies are listed 'Best First'.
Re: Functions not importing when module in folder
by choroba (Chancellor) on Mar 25, 2013 at 13:36 UTC
    After changing the path, you also have to change the package name to My_Module_Folder::My_Module. It might be more appropriate not to change the package name, though, but use lib instead.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Wow! Thank you so much! This has been bugging me so much.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025302]
Approved by Corion
help
Chatterbox?
Discipulus a missing semicolon after use LWP::UserAgent caused very strange behaviour and not the normal warning...
[choroba]: Yes, sometimes missing ; after the use clause just interprets the next line somehow and passes the result to the used module which could happily ignore it. Been there, seen that.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2017-02-28 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (398 votes). Check out past polls.