note
arturo
<p>The text of the tutorial doesn't mention the fact that the scope of the effect of <code>use vars</code> is file-level. This is, however, documented in the perldoc for [vars]:
<blockquote>
the "use vars" and
"use subs" declarations are not BLOCK-scoped. They are thus effective
for the entire file in which they appear.
</blockquote>
(it's also mentioned under "Pragmatic Modules" in the [perlmodlib] man page).
</p>
<p>
Even though its "maximum reach" is one file, the effects of <code>use vars</code> are still different than those of <code>our</code>, which was all I was trying to document in the tutorial.
</p>
<p>
So, the general answer to your question is that you can't do exactly what you say you want to do, and that's one of the points of <code>use strict</code>: if you're going to use a variable in a file, you have to declare it explicitly in that file; it encourages you to know where everything's coming from, and protects you from typos in variable names.
</p>
<p>
This doesn't mean your problem's insoluble, though. If, you want <code>inc.pl</code> to serve the function of being a "configuration script" that initializes a bunch of values so other scripts can use them, you can have it work this way: create one data structure (say, a hash), and 'export' that hash. This way, a script that uses <code>inc.pl</code> will only need to declare one variable with <code>our</code> or <code>use vars</code>; of course, with a hash, you lose the safety mentioned as one of the chief benefits of <code>use strict</code>.
</p>
<p>For this reason, instead of using a simple hash, you might want to have <code>inc.pl</code> be an object oriented module, but that's beyond the scope of this tutorial.
</p>
<p>HTH!</p>
<div class="pmsig"><div class="pmsig-23317">
<p class="mysig">If not P, what? Q maybe? <br />"Sidney Morgenbesser"</p>
</div></div>
66677
406891