I’m having trouble understanding how to export a package symbol to a namespace. I’ve followed the documentation almost identically, but it seems to not know about any of the exporting symbols.
mod.pm
#!/usr/bin/perl
package mod;
use strict;
use warnings;
require Exporter;
@ISA = qw(Exporter);
@EXPORT=qw($a);
our $a=(1);
1;
test.pl
$ cat test.pl
#!/usr/bin/perl
use mod;
print($a);
This is the result of running it
$ ./test.pl
Global symbol "@ISA" requires explicit package name at mod.pm line 10.
Global symbol "@EXPORT" requires explicit package name at mod.pm line 11.
Compilation failed in require at ./test.pl line 3.
BEGIN failed--compilation aborted at ./test.pl line 3.
$ perl -version
This is perl, v5.8.4 built for sun4-solaris-64int
It’s not telling you that you’re having a problem exporting
$a. It’s telling you that you’re having a problem declaring@ISAand@EXPORT.@ISAand@EXPORTare package variables and understrict, they need to be declared with theourkeyword (or imported from other modules–but that is not likely with those two). They are semantically different–but not functionally different–from$a.Nanny NOTE:
@EXPORTis not considered polite. ThroughExporterit dumps its symbols in the using package. Chances are if you think something is good to export–and it is–then it will be worth it for the user to request it. Use@EXPORT_OKinstead.