in reply to how to write a module

You should also browse the Tutorials section here at the Monastery. This is a good place to start: Simple Module Tutorial

Replies are listed 'Best First'.
Re^2: how to write a module
by baxy77bax (Deacon) on Jun 13, 2008 at 17:54 UTC
    i tried exactly the same example as the tutorial states and i'm receiving the same message:

    use strict; # you may need to set @INC here (see below) my @list = qw (J u s t ~ A n o t h e r ~ P e r l ~ H a c k e r !); #case 1 use MyModule; print func1(@list),"\n"; print func2(@list),"\n"; # case 2 # use MyModule qw(&func1); # print func1(@list),"\n"; # print MyModule::func2(@list),"\n"; # case 3 # use MyModule qw(:DEFAULT); # print func1(@list),"\n"; # print func2(@list),"\n"; # case 4 # use MyModule qw(:Both); # print func1(@list),"\n"; # print func2(@list),"\n"; ------------------------------------- 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;
    could it be because i'm on win32, or i'm just too tiered to see the obvious?
      Case 1 doesn't work because @EXPORT is empty. The symbols in @EXPORT_OK are available for importing but they are not automatically imported.
      The tutorial states that Case 1 will generate errors:
      Case 1: Because our module exports nothing by default we get errors...

      When I run Case 1, I get this error, as expected:

      Undefined subroutine &main::func1 called at ...

      Case 3 will also generate an error; Cases 2 and 4 should work properly.