I seem to have a lot of problems creating my first, simple package (this is actually my first package period). I am doing everything I should (I think), and it still does not work. Here is the package (I think you can call it a module):
package MyModule; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(func1 func2); %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], Both => [qw(&func1 &func2)]); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } 1;
I saved this module as MyModule (yes, it was saved as a .pm file) in Perl/site/lib (all my modules that are not built-in are stored here). Then I tried using this module inside a Perl script:
use strict; use warnings; my @list = qw (J ust ~ A nother ~ P erl ~ H acker !); use Mine::MyModule qw(&func1 &func2); print func1(@list),"\n"; print func2(@list),"\n";
I save this as my.pl Then I run my.pl and get this error:
Undefined subroutine &main::func1 called at C:\myperl\examplefolder\my.pl line 7.
Can someone explain why this is happening? Thanks in advance!
Note Yes, my examples were from Perl Monks . See Perl Monks "A Simple Modular Tutorial" . Thanks tachyon !
source share