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

What am I doing wrong here?
--- Foo.pm --- package Foo; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK); require Exporter; my $z = 1; @ISA = qw(Exporter); @EXPORT_OK = qw ($z); 1; --- test.pl --- use Foo qw(z); print $z;
Why will this not print one?

Replies are listed 'Best First'.
Re: Exporter usage?
by Aristotle (Chancellor) on Sep 02, 2002 at 03:43 UTC
    Because you are declaring $z as a file-scoped lexical using my. It has to be a package-global to be exported. You also need to use Foo qw($z); - note the sigil.

    Makeshifts last the longest.

      Hmm. Can I not declare $CGI = new CGI;@EXPORT_OK=qw($CGI);1;etc. and import the CGI ref in my other file?

        You can, but only if $CGI is not declared using my. This means either a use vars '$CGI'; or our $CGI (or don't declare it at all and don't use strict, but you should use strict).


        Confession: It does an Immortal Body good.