perlpal has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I've been reading about packages in perl and am having a prety tough time understanding a few concepts namely : -> nested packages (how do we nest packages?any practiacal purpose?) -> entries in the package symbol table : 'build_attack_hash' => *AttackDiv::build_attack_hash, (what does the typeglob do here?a brief on "typeglob" would also be appreciated) Thanks in Advance!
  • Comment on Doubts on "Nesting packages" and "typeglobs"

Replies are listed 'Best First'.
Re: Doubts on "Nesting packages" and "typeglobs"
by moritz (Cardinal) on Jan 21, 2009 at 06:52 UTC
    Typeglobs are explained in perlmod.

    Nested packages (like A::B::C) do not inherit any semantics from their "parents" (A or A::B), only the symbol tables are nested (but if you don't walk symbol tables in your program, you won't notice that).

      to expand on this, you cannot "nest" packages in the sense of C++ nested classes. At any given point, you only have a single package in which the current "compilation unit" exists. As said above, other than clarity, there is little to no value in the actual nesting, generally done through organizing files in sub-directories with the same name as the parent module, unless you are doing something absurdly complex with symbol tables (Don't).

      perlmod would give you a start on globs, but ultimately, the best answer, IMO, is that you shouldn't need to use them for anything until you get a much better knowledge of Perl. While fundamental, they are not a base part of the language, in the way that local variables or functions are.

Re: Doubts on "Nesting packages" and "typeglobs"
by GrandFather (Saint) on Jan 21, 2009 at 06:21 UTC

    -> is not related to packages. It is used for accessing reference values. Consider:

    use strict; use warnings; my @array = ("Hello world"); my $refArray = \@array; print $refArray->[0];

    Prints:

    Hello world

    Perl's payment curve coincides with its learning curve.
      OP is not asking about "->". Less haste in replying can go a long way..
        He used it twice, he should know what its for :)
Re: Doubts on "Nesting packages" and "typeglobs"
by targetsmart (Curate) on Jan 21, 2009 at 14:52 UTC
    Typeglobs are also explained in 'Advanced Perl Programming' book by Sriram Srinivasan, I personally love this book.
Re: Doubts on "Nesting packages" and "typeglobs"
by Anonymous Monk on Jan 21, 2009 at 13:57 UTC
    Do you see the message that appears at the very top of this node? It says:

    perlpal has asked for the WISDOM of the Perl Monks concerning the following QUESTION:

    It does not say:

    perlpal has asked for the FAITH of the Perl Monks concerning the following DOUBT

    You have been corrected time and time again on this. You really look like a troll considering how well written the rest of your English is.