Your questions been answered, but here's a bit more background information as to what's happening.

A typeglob is merely a value in a symbol table that points to package variables of the same name. For each typeglob, there are 6 slots (did I miss one? I keep thinking I missed one). For example, in package %SomePackage::, if we refer to *SomeVar, we're referring to a typeglob with the following slots:


  Symbol Table    Typeglob    Values
                                      
 %SomePackage::   *SomeVar    $SomeVar  (scalar)
                              @SomeVar  (array)
                              %SomeVar  (hash)
                              SomeVar   (format)
                              SomeVar   (file handle)
                              &SomeVar  (code)

In the above little diagram, you can refer to the scalar as $SomePackage::SomeVar.

For Perl to access a package variable, it must look up the typeglob in the appropriate symbol table and then check to see if the appropriate slot for the appropriate variable type has a value.

The local keyword merely takes the value of any package variable (which, of course, is a slot in a typeglob), saves the value, let's you reassign a value to that package variable and then restores the saved value when the scope exits. What this means is that you cannot use local on a lexically scoped variable (unless you predeclare it with our, but that's a lexically scoped package variable and will just make your head hurt). In other words, if you declare a variable with my, you don't use local on it. However, even with package variables you rarely want to use local unless you are either:

Note: like using strict, there are times to break these rules, but don't do that unless you can clearly explain why you shouldn't break them :)

Which brings us back to your original question of whether or not you can use that typeglob trick with strict. If you read further in the "Shiny Ball" book, you'll see that passing typeglobs in the manner described was used in older versions of Perl where references didn't exist. Now we have references and unless you're a Damian Conway or a related construct, I would not use this syntax. Use explicit references instead.

Cheers,
Ovid

Join the Perlmonks Setiathome Group.

New address of my CGI Course.


In reply to Re: Confused about typeglobs and references by Ovid
in thread Confused about typeglobs and references by Argel

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.