Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

You'll probably get more attention if you post a new question, rather than attempting to resurrect such an old discussion.

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.

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:

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.

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.

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";

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.

You seem a bit confused about package and lexical variables. I recommend that you take the time to read Dominus' excellent article Coping with Scoping.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg


In reply to Re^4: The difference between my and local by davorg
in thread The difference between my and local by cLive ;-)

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (10)
    As of 2014-07-31 09:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (248 votes), past polls