There's a bit that gets set when you 'import' a variable and this bit tells 'strict' that the variable has been 'declared'. use vars simply 'imports' the variable.
The heuristic that perl uses to detect when a variable is being 'imported' is to detect when the variable slot of a glob gets assigned to by code compiled into another package. Note that the importing has to be done before the code that uses the imported variable is compiled.
> perl -w
use strict;
BEGIN { *x= \$foo::y; }
print $x;
Variable "$x" is not imported at - line 3.
__END__
Global symbol "$x" requires explicit package name at - line 3.
Execution of - aborted due to compilation errors.
> perl -w
use strict;
BEGIN { package foo; *main::x= \$foo::y; }
print $x;
__END__
Name "foo::y" used only once: possible typo at - line 2.
Use of uninitialized value in print at - line 3.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|