wtd has asked for the wisdom of the Perl Monks concerning the following question:

I have a Simple module, design to illustrate the problem, rather than do anything useful.
package Simple; use strict; use warnings; use Exporter; my @ISA = qw(Exporter); my %EXPORT_TAGS = ("all" => [qw(&hello)]); Exporter::export_ok_tags("all"); sub hello { print "Hello\n"; } 1;

Now, in theory, the following should work.

perl -Mstrict -Mwarnings -e "use Simple qw(:all); &hello"

However, I get the following error.

Undefined subroutine &main::hello called at -e line 1.

Am I incorrect in thinking that exporting "hello" means it should end up in the main package?

Replies are listed 'Best First'.
Re: Am I doing something wrong with Exporter?
by bart (Canon) on Dec 04, 2004 at 09:29 UTC
    @ISA and %EXPORT_TAGS must be package variables — globals. Otherwise, Exporter simply would never have access to them. Lexicals just won't work. Drop the "use strict" and both the instances of "my", and it works.

    If you want to keep using strict, replace "my" with "our", or, if you want it to work on older perls too, add a line

    use vars qw(@ISA %EXPORT_TAGS);
    and there is no longer a need for use of "our".
      Thank you.