Vera
Vera

Reputation: 91

Attempt to use @INC and call function on demand

I am trying to learn how to use a .pm file. I created 2 files:

the structure of the directories is as following:

 ---------------         ------------     ---------------
 | firstdir ---|------> |seconddir--|-> | MyModule.pm |
 | MyScript.pl |         ------------    ---------------
  ---------------

note: firstdir and seconddir are directories when I run the command Perl MyScript.pl I receive the following error:

Undefined subroutine &main::func1 called at MyScript.pl line 21

can you help me figure out what is wrong please?

Upvotes: 2

Views: 79

Answers (3)

Krishnachandra Sharma
Krishnachandra Sharma

Reputation: 1342

@EXPORT = qw(func1 func2);

You need to add the names of the symbols in the @EXPORT array in order to access them from you script.

Upvotes: 0

RobEarl
RobEarl

Reputation: 7912

Your package name is wrong, it should be:

package seconddir::MyModule

Then you should call func2 with:

print seconddir::MyModule::func2(@list),"\n";

or by exporting it, as with func1.

Upvotes: 2

Nikhil
Nikhil

Reputation: 2308

func1 should be in the @EXPORT array in the module MyModule.pm if you want to call it directly as func1 in your main script.

Upvotes: 1

Related Questions