note
davorg
<p>You'll probably get more attention if you post a new question, rather than attempting to resurrect such an old discussion.</p>
<p>The error message you get seems pretty clear to me. You are attempting to use "local" on a lexical variable - and "local" can only be used on package variables.</p>
<p>If you see an error message that you don't understand then it's a good idea to add "use diagnostics" to your code in order to see an expanded description of the error. In this case it says:</p>
<blockquote><i>You used local on a variable name that was previously declared as a lexical variable using "my". This is not allowed. If you want to localize a package variable of the same name, qualify it with the package name.</i></blockquote>
<p>But you need to ask yourself why you're doing it like this. What are you hoping to achieve by localising the variable here? I think that it's probably clearer if you create a new variable, which will be removed at the end of the block.</p>
<code>
use strict;
my $tt = 3.14159;
{
my $inner_tt = 3;
print "In block, \$tt = $tt\n";
print "In block, \$inner_tt = $inner_tt\n";
}
print "Outside block, \$tt = $tt\n";
print "Outside block, \$inner_tt = $inner_tt\n";
</code>
<p>Your code is further confused by the references to $::tt. Those are references to a package variable called $tt. And you never declare a package variable of that name.</p>
<p>You seem a bit confused about package and lexical variables. I recommend that you take the time to read [Dominus]' excellent article [http://perl.plover.com/FAQs/Namespaces.html|Coping with Scoping].</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-2680">
-- <br>
<<a href="http://dave.org.uk">http://dave.org.uk</a>>
<p><i>"The first rule of Perl club is you do not talk about
Perl club."</i><br> -- Chip Salzenberg</p>
</div></div>
94007
578736