If you find yourself in this situation, and think you need to declare a global then try this:
If you would like to avoid globals ( this is common wisdom) you might consider defining a subroutine to return your values:use vars qw(%friends);
then you can do this in your main codesub getFriends { # Initializes my little hash our %friends = (Paul => 1, Suzie => 1); return %friends; }
If you want to happily ignore scopes, you can do this in your main file:use Friends; my %friends = &getFriends(); # for lexical scope
in outsidefile:require "outsidefile"; print %friends;
This is BAD, and strict will complain about this.# # guess what? I'm in main's scope !!! # %friends = (Paul => 1, Suzie => 1);
Can anyone explain how to properly create two files that share the same package name (name space) that works under strict?
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
In reply to Re: Re: IMport a variable from another file
by freddo411
in thread IMport a variable from another file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |