in reply to Re^3: type glob
in thread type glob

The place that I'd look for documentation on the symbol table is Symbol Tables, but I don't see any use of the term ‘dynamic variables’ there (and I wouldn't expect to see one in the Perl documentation; it's not a standard term). Did you look somewhere else?

I read the Symbol Table section of the docs in perlmod before posting, but I don't see how anyone would know after reading that section that my variables are not included in the symbol table. After I read that, I thought all variables in your program were included in the symbol table. It made sense to me that they would be.

I got the term "dynamic variables" from the introductory paragraph higher up on the page:

A package statement affects only dynamic variables--including those you've used local() on--but not lexical variables created with my().

Reading the term 'dynamic variable' didn't make any sense to me.

Replies are listed 'Best First'.
Re^5: type glob
by ikegami (Patriarch) on Nov 17, 2009 at 22:19 UTC

    I thought all variables in your program were included in the symbol table. It made sense to me that they would be.

    Then you couldn't have multiple variables with the same name, as in:

    my $x; sub foo { my $x; my $x; { my $x; } } sub bar { my $x; }
      Then you couldn't have multiple variables with the same name, as in:
      my $x; sub foo { my $x; my $x; { my $x; } } sub bar { my $x; }

      It seems to me that your code behaves almost exactly like

      our $x; sub foo { local $x; local $x; { local $x; } } sub bar { local $x; }
      (except that localising a variable twice doesn't warn, whereas mying twice does) *. Thus, I'm not sure that it's accurate to say that you can't have two variables, both with the same name, in the symbol table **. (You might respond that you can only access one of them at a time, but that's true for lexicals, too.)

      * Of course, since neither code does anything, this might be an even more vacuous statement than is usual for me. :-)
      ** Ah, but the $x of local $x is the same variable as that of our $x, whereas the $x of my $x is not the same variable as that of the other my $x.

        local doesn't create variables. It just backs up the value of the variable and restores it later. While it reduces the problems of using global variables, it doesn't remove them all.
Re^5: type glob
by JadeNB (Chaplain) on Nov 17, 2009 at 20:33 UTC
    I read the Symbol Table section of the docs in perlmod before posting, but I don't see how anyone would know after reading that section that my variables are not included in the symbol table.
    I think it's a good point; I've read the linked passage again, and I also can't see how one would find out from that that only package variables are in stashes. The closest I can come in a few seconds' search is Symbolic references. In this case, I'd say that the way you know is that you ask a question like yours and someone tells you. :-)
    I got the term "dynamic variables" from the introductory paragraph higher up on the page
    Interesting! Well, I guess that there's a documentation patch waiting to be submitted.
        perlguts explains stash
        I think that that's much the same as saying that the Perl source explains the workings of all of Perl—it's true, but not necessarily helpful for someone who doesn't want to dive deep into the innards. In particular, I think that one still can't extract from perlguts the fact that the symbol table is for package variables.
        perlguts explains stash

        A little too technical for me at this point.

        http://www.perlmonks.org/?node_id=520303

        Thanks. That's very well written. Required reading. My favorite section:

        When to Use my and When to Use local

        Always use my; never use local.

        Wasn't that easy?

Re^5: type glob
by przemo (Scribe) on Nov 17, 2009 at 20:52 UTC
    I read the Symbol Table section of the docs in perlmod before posting, but I don't see how anyone would know after reading that section that my variables are not included in the symbol table.

    Using quantifier like anyone is dangerous: no one knows how smart others are. :)

    For example, one may be guessing just the opposite: if the variable is "my", then it is not "others'", so it is probably not in package's symbols table for others to modify.