in reply to Importing variables (not functions) from in-file packages
Your original code seems to work as long as the scalar $globalVar is exported using its correct name, i.e., using the $ sigil.
c:\@Work\Perl\monks>perl -wMstrict -le "MyPackage->import; print $::globalVar; $::globalVar=1; print $::globalVar; myfunction(); BEGIN{ package MyPackage; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw($globalVar myfunction); our $globalVar = 42; sub myfunction { print 'hi from ', __PACKAGE__; } } " 42 1 hi from MyPackage
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Importing variables (not functions) from in-file packages
by puterboy (Scribe) on Feb 12, 2014 at 19:14 UTC | |
by AnomalousMonk (Archbishop) on Feb 12, 2014 at 20:29 UTC | |
by Anonymous Monk on Feb 12, 2014 at 19:55 UTC |
In Section
Seekers of Perl Wisdom