There's more than one way to do things | |
PerlMonks |
Re: Scope of variables using strictby btrott (Parson) |
on Mar 22, 2001 at 23:45 UTC ( [id://66428]=note: print w/replies, xml ) | Need Help?? |
You have several problems: one that I can see is with your code,
another is with your implementation in general. First, the problem with the code. You have, in control.cgi: Then in required.cgi, you have: Your problem is that the var in control.cgi isn't in package main. my variables aren't in any package; their scope is lexical to the file or the surrouding block. Which means that your code in required.cgi has *no way* of accessing the $TestVar in control.cgi. So right there, you have a problem: there's no way you can get that to work if you're using lexical variables in control.cgi and trying to access them in required.cgi. And this comes back to your implementation: this is really not the best way to do this. If the code in required.cgi is to be used by a lot of scripts, you should package it up into either a library of exportable variables and functions or make some sort of OO interface (but *only if that makes sense*). From your message it sounds like what you may want most is the former, a library of exportable functions and variables. Take a look at perlmod and Exporter for that.
In Section
Seekers of Perl Wisdom
|
|