in reply to Exporting scalars from a module

OK, what you think you are doing is not what you are actually doing...

The problem is the my(...). This declares a whole bunch of lexically scoped variables, which are completely different to the symbols in the @EXPORT array. Things in the @EXPORT... structures are things in the packages symbol table - and lexically scoped variables are most definitely not in the symbol table.

I'll say again - the things in the my() are not the same as the things in the @EXPORT array. This is the crux of your issue.

The quickest solution is to change the my to our (if your perl has this new-ish keyword) or change the my to use vars qw(...) and remove the commas in the list.

package thingy; use warnings; use strict; use Exporter; use vars qw(@ISA @EXPORT $VERSION); use vars qw($PACKAGE_REQUEST_ID $BUGNUMBER $KBARTICLE $DISTMETHOD $MIN +SP $MAXSP $ISNONINSTALLINGPKG $JOBBRANCHNAME $HOTPATCHBINARIES $BINAR +IESAFFECTED $BUGTITLE); @ISA = qw(Exporter); @EXPORT = qw(Execute GetValue $PACKAGE_REQUEST_ID $BUGNUMBER $KBARTICL +E $DISTMETHOD $MINSP $MAXSP $ISNONINSTALLINGPKG $JOBBRANCHNAME $HOTPA +TCHBINARIES $BINARIESAFFECTED $BUGTITLE); $VERSION = '1.00'; ...
The longer solution is to read every article in Tutorials on variables. Only then may you claim true mastery.

+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;

Replies are listed 'Best First'.
Re: Re: Exporting scalars from a module
by chip (Curate) on May 03, 2004 at 15:32 UTC
    Rule #1 of programming: Repetition is evil.
    my @xvars; BEGIN { @xvars = qw($PACKAGE_REQUEST_ID $BUGNUMBER $KBARTICLE $DISTMET +HOD $MINSP $MAXSP $ISNONINSTALLINGPKG $JOBBRANCHNAME $HOTPATCHBINARIE +S $BINARIESAFFECTED $BUGTITLE) } use vars ( qw(@ISA @EXPORT $VERSION), @xvars ); require Exporter; @ISA = qw(Exporter); @EXPORT = ( qw(Execute GetValue), @xvars );

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      How can I enable use strict and not use my to declare the variables? (The version of perl we use does not support the our keyword):

      package ExitCode; my @varsToExport = qw(%exitCodes $EXIT_SUCCESS $EXIT_GENERAL_FAILURE $ +EXIT_CHANGELIST_CONSUMED $EXIT_FUTURE_CHANGELIST); require Exporter; use vars (qw(@ISA @EXPORT), @varsToExport); @ISA = qw(Exporter); @EXPORT = qw(@varsToExport); %exitCodes; # Define exit codes $EXIT_SUCCESS = 0;
        You need to put your @varsToExport in a BEGIN block.
        my @varsToExport; BEGIN { @varsToExport = qw(...); } use vars @varsToExport; @EXPORT = qw(@varsToExport);
        Or you can upgrade your perl. :-)