the string eval will run at runtime, which is far too late for the strict 'vars' check to find out that %hash1 has been declared
Did you mean "hasn't been declared"? If yes, then note that the strict check still kicks in, although as you said, at runtime. If you meant it as written, then this doesn't make sense to me... use strict 'vars'; has nothing to do with variables being declared twice (that's just a warning, in the shadow category, and it doesn't happen if the variables are in different scopes).
$ perl -wMstrict -le 'eval "%hash1=(); 1" or warn "<<$@>>"'
<<Global symbol "%hash1" requires explicit package name (did you forge
+t to declare "my %hash1"?) at (eval 1) line 1.
>> at -e line 1.
$ perl -wMstrict -le 'my %hash1; my %hash1; print "Foo";'
"my" variable %hash1 masks earlier declaration in same scope at -e lin
+e 1.
Foo
$ perl -wMstrict -le 'my %hash1; { my %hash1; } print "Foo";'
Foo
$ perl -wMstrict -le 'my %hash1; eval "my %hash1;"; print "Foo";'
Foo
-
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.
|