example
out.pl:
(my|our|local|global|whatever???) var = "test";
require("inside.pm");
inside.pm:
print $var;
I don’t want to use packages – it’s overwhelming my needs 🙂
thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It will work with
our.This works because
ourmakes$varglobal, andinside.pmis being executed in the scope with$vardefined. Not sure it is recommended technique, but it is an interesting question nevertheless!EDIT: Need to clarify (okay patch) the answer based on a comment:
From the documentation on the Perl function
our:So using
our, we get$varwith the current package (here probablymain) and we can use it in its scope. In effect it is then “global” to the code in the file you are requiring-in.A true global is introduced without the
our, because variables default to global. But I don’t know anyone that would recommend them.