![]() |
|
Problems? Is your data what you think it is? | |
PerlMonks |
Importing variables (not functions) from in-file packagesby puterboy (Scribe) |
on Feb 12, 2014 at 15:27 UTC ( #1074633=perlquestion: print w/replies, xml ) | Need Help?? |
puterboy has asked for the wisdom of the Perl Monks concerning the following question:
For various portability reasons, I need to include a couple of custom packages in the same file as my application.
I have no problem wrapping each package in a BEGIN block and accessing methods the usual way. I can also export subroutines using exporter/import. However, I can't seem to export global variables. My code uses the following paradigm: Running, yields the error 'symbol "$globalVar" requires explicit package name' When I dump the namespace for %main::, I get: So, $globalVar seems to be in the namespace, I just can't seem to be able to use it (unless of course I explicitly address it using its originating namespace location as $MyPackage::globalVar) If I put the package in a separate file and include it using 'use MyPackage', I get the same listing in the %main:: namespace as above but I am then able to access the global error directly without error. Any ideas what is causing $globalVar not to be recognized when the package is in the same file as main?
Back to
Seekers of Perl Wisdom
|
|