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


in reply to Of Symbol Tables and Globs

Perl has two different types of variables - lexical and dynamic.

I think package global is a much better description than dynamic.

All these slots are accessible bar the FORM slot. Why this is I don't know...

Because it's spelled FORMAT.

nother thing to be noted from the above example is that you can't assign toglob slots directly,

Judging by your next paragraph, I think you need to clarify what you mean by assign directly.

Replies are listed 'Best First'.
Re: Re: Of Symbol Tables and Globs
by demerphq (Chancellor) on Nov 08, 2002 at 20:00 UTC
    I think package global is a much better description than dynamic.

    I think neither is that good. Package global implies that it is only global to the package. Dynamic is probably the better term, problem is that almost nobody will know what it means until they've learned enough perl to not care what term is used.

    I agree with your point about the assigning directly.

    --- demerphq
    my friends call me, usually because I'm late....

      I think saying "lexical (my), and dynamic (use vars, our (with caveats), undeclared (except under use strict), all subs, direct playing with globs (see below), filehandles/dirhandles, and formats)" would do the trick. You might just want to say "(all others)" instead of listing all of those.

      Also, more importantly, you've got a terminology mismatch in the whole document: symbol tables aren't like hashes, they are hashes. %main:: (AKA %::, which you might want to mention explicitly) is a hash. *main::{somevar} isn't a hash, it's a hash element, which contains a glob, which is like a hash in many ways.


      Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

        Also, more importantly, you've got a terminology mismatch in the whole document: symbol tables aren't like hashes, they are hashes.
        They are accessed like hashes, but they are not hashes. It could perhaps be said that hashes are not symbol tables but symbol tables can be treated exactly like hashes except they can only store globs and have various sorts of magical behaviour associated. But that's a little confusing and long-winded.
        %main:: (AKA %::, which you might want to mention explicitly)
        I'll see if I can slip it in there somewhere :)

        Thanks for the input!

        _________
        broquaint

Re: Re: Of Symbol Tables and Globs
by John M. Dlugosz (Monsignor) on Nov 08, 2002 at 19:47 UTC
    *glob{FORMAT} is not mentioned in my copy of perlref where this {THING} syntax is described.

    Was that added later? What version? What would you assign it to?

    It also notes that the {IO} slot comingles two distinct values, the file handle and directory handle.

      I believe the FORMAT slot has been present since the birth of typeglobs, but I don't have the source code to prove it. It's like the IO slot -- you can't really assign to it directly. (Since formats are associated strongly with filehandles, it makes a certain amount of sense.)

Re: Re: Of Symbol Tables and Globs
by broquaint (Abbot) on Nov 09, 2002 at 15:41 UTC
    I think package global is a much better description than dynamic.
    I'll go with this description then. I went with dynamic because I thought it was a more symmetrical description, but I can see that it is a little too technical for a tutorial.
    Because it's spelled FORMAT.
    Indeed it is, but it's still totally inaccessible through native perl code i.e you can't access the glob slot at all.
    ## IO example open(0); print "[", *0{IO}, "]", $/; ## FORMAT example format foo = . print "[", *foo{FORMAT}, "]", $/ __output__ [IO::Handle=IO(0x80fbb0c)] []
    Judging by your next paragraph, I think you need to clarify what you mean by assign directly.
    Alrighty, I'll sort that out.

    Thanks for the input :)

    _________
    broquaint