note
John M. Dlugosz
<I>Perl has two different types of variables - lexical and dynamic</I><P>
I agree with [chromatic], that's not a dynamic variable per-se, that's a global variable. Saving it and restoring it via local is a separate effect and only meaningful when a variable is shared among functions, but that doesn't mean it must be a package global to be "dynamic". Although <code>local</code> doesn't work, a lexical variable at package scope (or in a block surrounding several related functions) could also push/pop the value in a similar manner.<P>
<I>but the most common way in which they are created is through the package declaration...Notice how we didn't use a package declaration there? </I><P>
That's confusing. The first should say that the symbol table is created when a symbol in a package is mentioned. This doesn't have to be done by using the local package within that package, just refer to a variable anywhere. Saying it's created by the package declaration just introduces more rules later, but the general rule would be right in all cases.<P>
<I>The double colons allow the separation of symbol tables</I><P>Huh?<P>
<I>we treat it like we would a hash </I><P>
It <I>is</I> a hash; you just said so. I think you mean "...would any other hash.".<P>
Ever assign something to a symbol table hash entry that wasn't a glob?<P>
Note that <code>$globtut::{variable} = \$foo;</code> means different things depending on whether there is already an entry by that name or it is added by the assignment. Contrast with <code>${"*globtut::variable"}= \$foo;</code> which auto-vivifies <I>as a glob</I>.<P>
<I>To access the individual slots just treat the glob like a hash e.g</I><P>
I would prefer something like, "...use a similar syntax to accessing a hash".<P>
<code>${ *scalar{FOO} } = "the FOO data type";
</code>
Your error is not due to any protection on symbol tables. Rather, *scalar{FOO} gives undef (rather than a run-time error; go figure) and then the $ dereference gives the error. It's not auto-vivifying like a hash entry would, but it's not a hash! It's a special hash-like syntax. Interesting that the reading of it is not an error.<P>
<I>Another thing to be noted from the above example is that you can't assign toglob slots directly, only through dereferencing them.</I><P>
Very interesting... I always thought I could assign a reference to it, just never bothered because you don't have to use the subscript on the left-hand-side since it knows what kind of reference you are assigning. That is, <code>*scalar= \$x</code> instead of <code>*scalar{SCALAR}=\$x</code><P>
<I>we have succesfully imported Foo's subroutines into the main package and nothing else </I><P>
1) you imported into globtut package, not main package.
2) the grammar is compound-noun((noun(main package) AND noun(nothing else)), which I don't think is what you meant.
A couple typos. missing space, "the the", "callers symbol table", "callers package".<P>
—John
211441
211441