If your package relies on the availability of a global found in the main program (which would be $main::var, as already mentioned), then you will be unable to use it as a part of any program which does not contain that same variable and make it available as a global under the same name. In your example of what you (think you) want, using Mypackage in any program which does not provide a global $main::var will mean that you then have to remember to never call printthis.
Packages should not impose requirements of this sort on the code which uses them.
In most cases, the correct approach for sharing variables between a package and other code would be to define it in the package and export it to the code using the package. But that may not be well-suited to what you're actually attempting to accomplish. So what are you actually attempting to accomplish, so we can advise on the best way to do it?
In reply to Re: Access variable from inside a package?
by dsheroh
in thread Access variable from inside a package?
by tamaguchi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |